日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
jpa技術總結(jié)

jpa是ejb的基礎。現(xiàn)在ejb還沒入門呢,但一定要學下去。從tc中應用ejb的程度來看,這技術在大的應用程序中應用很廣泛。
雖然這次做得很失敗,orm.xml還是沒完全弄明白怎么寫。但還是將自己所了解的寫上來。HelloWorld example來自
首先是persistence.xml文件

成都網(wǎng)站建設哪家好,找創(chuàng)新互聯(lián)建站!專注于網(wǎng)頁設計、網(wǎng)站建設公司、微信開發(fā)、微信小程序開發(fā)、集團企業(yè)網(wǎng)站建設等服務項目。核心團隊均擁有互聯(lián)網(wǎng)行業(yè)多年經(jīng)驗,服務眾多知名企業(yè)客戶;涵蓋的客戶類型包括:成都加固等眾多領域,積累了大量豐富的經(jīng)驗,同時也獲得了客戶的一致稱贊!

xml 代碼

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence  
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"  
version="1.0">  
  
org.hibernate.ejb.HibernatePersistenceprovider>  
 
Holidayclass>  
-->  
  
  
  
value="oracle.jdbc.driver.OracleDriver" />  
value="jdbc:oracle:thin:@localhost:1521:tctest" />  
  
  
value="org.hibernate.dialect.OracleDialect" />  
properties>  
persistence-unit>  
  
persistence>

接著是orm.xml文件,自己組件的沒做好,但helloworld還是沒問題

xml 代碼

xml version="1.0" encoding="UTF-8"?>   
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd" version="1.0">  
  
  
  
  
  
  
id>  
attributes>  
mapped-superclass>  
  
  
table>  
  
  
  
  
  
attribute-override>  
  
  
  
  
basic>  
attributes>  
entity>  
entity-mappings>

實體定義,用了繼承,不用繼承的早就解決了。注意@MappedSuperclass ,@entity,@Id的用法。需要jpa實現(xiàn)的包。我用的hibernate,這些包主要來自hibernate core 3.2.0g, hibernate entitymanager 3.2.0 and hibernate annotation 3.2. 具體要用其中的哪些我還沒怎么弄明白,一個個加吧。

java 代碼

package hello;
import java.io.Serializable;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
@MappedSuperclass
public class BaseMessage implements Serializable {
private static final long serialVersionUID = 4585624359812256628L;
private Long id;
public BaseMessage() {
super();
}
@Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
package hello;
import javax.persistence.Entity;
@Entity
public class Message extends BaseMessage {
private static final long serialVersionUID = -7660981805652763488L;
private String text;
Message() {
}
public Message(String text) {
this.text = text;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}

persistence 過程:

java 代碼

package hello;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
public class HelloWorldEM {
public static void main(String[] args) {
// Start EntityManagerFactory
EntityManagerFactory emf = Persistence.createEntityManagerFactory("helloworld");
// First unit of work
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
Message message = new Message("Hello World");
em.persist(message);
Long msgId = message.getId();
tx.commit();
em.close();
// Second unit of work
EntityManager newEm = emf.createEntityManager();
EntityTransaction newTx = newEm.getTransaction();
newTx.begin();
List messages = newEm.createQuery("select m from Message m order by m.text asc").getResultList();
System.out.println(messages.size() + " message(s) found");
for (Object m : messages) {
Message loadedMsg = (Message) m;
System.out.println(msgId.longValue());
System.out.println(loadedMsg.getText());
}
newTx.commit();
newEm.close();
emf.close();
}
}

【編輯推薦】

  1. 詳解XML與J2EE組合技術的精髓
  2. J2EE的13種核心技術簡介
  3. 深入掌握Java技術 EJB調(diào)用原理分析

網(wǎng)站名稱:jpa技術總結(jié)
網(wǎng)頁鏈接:http://www.5511xx.com/article/codddho.html