´«ÖDz¥¿Íjavaѧϰ jpa³õ²½
ÎÒ½ñÌìѧϰÁËÐìÀÏʦ½²µÄjpa£¬ÎÒ×öÁ˼òµ¥µÄ±Ê¼Ç£º
JPA(Java Persistence API)ÊÇSun¹Ù·½Ìá³öµÄJava³Ö¾Ã»¯¹æ·¶¡£ËüΪJava¿ª·¢ÈËÔ±ÌṩÁËÒ»ÖÖ¶ÔÏó/¹ØϵӳÉ乤¾ßÀ´¹ÜÀíJavaÓ¦ÓÃÖеĹØϵÊý¾Ý¡£ËûµÄ³öÏÖÖ÷ÒªÊÇΪÁ˼ò»¯ÏÖÓеij־û¯¿ª·¢¹¤×÷ºÍÕûºÏORM¼¼Êõ£¬½áÊøÏÖÔÚHibernate¡¢TopLinkµÈORM¿ò¼Ü¸÷×ÔΪӪµÄ¾ÖÃæ¡£ÖµµÃ×¢ÒâµÄÊÇ£¬JPAÊÇÔÚ³ä·ÖÎüÊÕÁËÏÖÓÐHibernate¡¢TopLinkµÈORM¿ò¼ÜµÄ»ù´¡ÉÏ·¢Õ¹¶øÀ´µÄ£¬¾ßÓÐÒ×ÓÚʹÓá¢ÉìËõÐÔÇ¿µÈÓŵ㡣´ÓÄ¿Ç°µÄ¿ª·¢ÉçÇøµÄ·´Ó¦ÉÏ¿´£¬JPAÊܵ½Á˼«´óµÄÖ§³ÖºÍÔÞÑÆäÖоͰüÀ¨ÁËSpringÓëEJB3.0µÄ¿ª·¢ÍŶӡ£×ÅÑÛδÀ´¼¸ÄêµÄ¼¼Êõ×ßÏò£¬JPA×÷ΪORMÁìÓò±ê×¼»¯ÕûºÏÕßµÄÄ¿±êÓ¦¸Ã²»ÄÑʵÏÖ¡£
JPAµÄ×ÜÌå˼ÏëºÍÏÖÓÐHibernate¡¢TopLinkµÈORM¿ò¼Ü´óÌåÒ»Ö¡£×ܵÄÀ´Ëµ£¬JPA°üÀ¨ÒÔÏÂ3·½ÃæµÄ¼¼Êõ£º
ORMÓ³ÉäÔªÊý¾Ý
JPAÖ§³ÖXMLºÍJDK 5.0×¢ÊÍ£¨Ò²¿ÉÒë×÷×¢½â£©Á½ÖÖÔªÊý¾ÝµÄÐÎʽ£¬ÔªÊý¾ÝÃèÊö¶ÔÏóºÍ±íÖ®¼äµÄÓ³Éä¹Øϵ£¬¿ò¼Ü¾Ý´Ë½«ÊµÌå¶ÔÏó³Ö¾Ã»¯µ½Êý¾Ý¿â±íÖС£
Java³Ö¾Ã»¯API
ÓÃÀ´²Ù×÷ʵÌå¶ÔÏó£¬Ö´ÐÐCRUD²Ù×÷£¬¿ò¼ÜÔÚºǫ́ÌæÎÒÃÇÍê³ÉËùÓеÄÊÂÇ飬¿ª·¢Õß¿ÉÒÔ´Ó·±ËöµÄJDBCºÍSQL´úÂëÖнâÍѳöÀ´¡£
²éѯÓïÑÔ
ÕâÊdz־û¯²Ù×÷ÖкÜÖØÒªµÄÒ»¸ö·½Ã棬ͨ¹ýÃæÏò¶ÔÏó¶ø·ÇÃæÏòÊý¾Ý¿âµÄ²éѯÓïÑÔ²éѯÊý¾Ý£¬±ÜÃâ³ÌÐòµÄSQLÓï¾ä½ôÃÜñîºÏ¡£
JPA²»ÊÇÒ»ÖÖеÄORM¿ò¼Ü£¬ËûµÄ³öÏÖÖ»ÊÇÓÃÓڹ淶ÏÖÓеÄORM¼¼Êõ£¬Ëû²»ÄÜÈ¡´úÏÖÓеÄHibernate¡¢TopLinkµÈORM¿ò¼Ü¡£Ïà·´£¬ÔÚ²ÉÓÃJPA¿ª·¢Ê±£¬ÎÒÃÇÈÔ½«Ê¹Óõ½ÕâЩORM¿ò¼Ü£¬Ö»ÊÇ´Ëʱ¿ª·¢³öÀ´µÄÓ¦Óò»ÔÙÒÀÀµÓÚij¸ö³Ö¾Ã»¯ÌṩÉÌ¡£Ó¦ÓÿÉÒÔÔÚ²»Ð޸ĴúÂëµÄÇé¿öÏÂÔÚÈκÎJPA»·¾³ÏÂÔËÐУ¬ÕæÕý×öµ½µÍñîºÏ£¬¿ÉÀ©Õ¹µÄ³ÌÐòÉè¼Æ¡£
JPA±à³Ì½¨Ä££ºÊµÌåÊÇPOJO(²»ÐèҪʵÏÖEntityBean)£¬Ê¹ÓÃ×¢½â±íÃ÷ʵÌå(²»ÐèҪʹÓò¿ÊðÃèÊö·û)
JpaµÄºËÐÄ´úÂ룺
EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1")
EntityManager em = emf.createEntityManager();
em.xxx();
em.close();
emf.close();
jpaµÄÓ³É䣺
Ó³ÉäʵÌå @Entity @Table(name="USERS")
Ó³ÉäÊôÐÔ£º@id
JPA¹Øϵ ManyToOne/OneToMany
@ManyToOne/@OneToMany
Class Order{
@ManyToOne
Customer customer ;
Class Customer{
@OneToMany(mappedBy
Ïà¹ØÎĵµ£º
/**
* ### Õæ難µÄ題Ä¿: ¹·Æ¨ÑÝËã·¨ (測資ºÜ機車)
* 測驗結¹û: x.xx0 ms
* 測驗ÈÕÆÚ: 200y-mm-dd
* @author Raymond Wu (Сè°Íè)
*/
public class Main {
// 輸Èë緩衝區 (緩衝¿Õ ......
·½·¨Ò»£º
Map map = new HashMap();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
}
·½·¨¶þ£º
Map map = n ......
ÎÒ½ñÌìѧϰÁËÐìÀÏʦ½²µÄhibernate֪ʶ£¬ÎÒ×öÁ˼òµ¥µÄ±Ê¼Ç£º
Ò»¡¢Hibernate
a) Á¬½ÓjavaÓ¦ÓóÌÐòºÍ¹ØϵÐÍÊý¾Ý¿âµÄÖмä¼þ£¬¶ÔJDBC API·â×°£¬¸ºÔð¶ÔÏó³Ö¾Ã»¯
b) λÓڳ־û¯²ã£¬·â×°ËùÓеÄÊý¾Ý·ÃÎÊϸ½Ú£¬Ê¹ÒµÎñÂß¼²ã¸ü¹Ø×¢ÓÚÒµ ......
ÎÒ½ñÌìѧϰÁËluceneµÄһЩ֪ʶ£¬ÎÒ×öÁ˼òµ¥µÄ±Ê¼Ç£º
Ë÷ÒýÎļþ½á¹¹£º
µ¹ÅÅË÷Òý£¬Ë÷Òý¶ÔÏóÊÇÎĵµÖеĵ¥´ÊµÈ£¬ÓÃÀ´´æ´¢ÕâЩµ¥´ÊÔÚÒ»¸öÎĵµÖеÄλÖá£ÀýÈ磬ÓÐЩÊéÔÚ×îºóÌṩµÄË÷Òý£¨µ¥´Ê——Ò³ÂëµÄ¶ÔÓ¦ÁÐ±í£©£¬¾Í¿ÉÒÔ¿´³ÉÊÇÒ»ÖÖµ¹ÅÅÐòË÷Òý¡£¿ÉÒÔͨ¹ýһЩ¹Ø¼ü×Ö£¬ÔÚÈ«ÊéÖмìË÷³öÓëÖ®Ïà¹ØµÄ²¿
Ë÷ÒýÎ ......