´«Ö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
Ïà¹ØÎĵµ£º
ÔÚÃüÁîÐнçÃæÓÃnative2ascii¹¤¾ß
1.½«ºº×ÖתΪUnicode:
C:\Program Files\Java\jdk1.5.0_04\bin>native2ascii
²âÊÔ
\u6d4b\u8bd5
2.½«Unicodeת»»Îªºº×Ö:
C:\Program Files\Java\jdk1.5.0_04\bin>native2ascii -reverse ......
ÏÂÃæÒÔ±àÒë /src/com/dream/io/ScannerTest.javaΪʾÀý£º
1¡¢ÓÃjavac±àÒë.javaÎļþʱ£¬½øÈësrcĿ¼ºó£¬ÊäÈë javac com/dream/io/ScannerTest.java£¬ »Ø³µ£¬¼´¿É±àÒëScannerTest.javaÎļþΪ.classÎļþ£»Ò²¿É£¬½øÈë /src/com/dream/io/ Ŀ¼ºó£¬ ÊäÈë javac ScannerTest.java£¬ »Ø³µ£¬Ò²¿É±àÒë ScannerTest.javaÎļþΪ .clas ......
±à¼¹¤³ÌµÄ.projectÎļþ£º
Ìí¼Ó
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
µ½
<natures>
…
& ......
ÎÒ½ñÌìѧϰÁËÐìÀÏʦ½²µÄhibernate֪ʶ£¬ÎÒ×öÁ˼òµ¥µÄ±Ê¼Ç£º
Ò»¡¢Hibernate
a) Á¬½ÓjavaÓ¦ÓóÌÐòºÍ¹ØϵÐÍÊý¾Ý¿âµÄÖмä¼þ£¬¶ÔJDBC API·â×°£¬¸ºÔð¶ÔÏó³Ö¾Ã»¯
b) λÓڳ־û¯²ã£¬·â×°ËùÓеÄÊý¾Ý·ÃÎÊϸ½Ú£¬Ê¹ÒµÎñÂß¼²ã¸ü¹Ø×¢ÓÚÒµ ......
ÎÒ½ñÌìѧϰÁËluceneµÄһЩ֪ʶ£¬ÎÒ×öÁ˼òµ¥µÄ±Ê¼Ç£º
Ë÷ÒýÎļþ½á¹¹£º
µ¹ÅÅË÷Òý£¬Ë÷Òý¶ÔÏóÊÇÎĵµÖеĵ¥´ÊµÈ£¬ÓÃÀ´´æ´¢ÕâЩµ¥´ÊÔÚÒ»¸öÎĵµÖеÄλÖá£ÀýÈ磬ÓÐЩÊéÔÚ×îºóÌṩµÄË÷Òý£¨µ¥´Ê——Ò³ÂëµÄ¶ÔÓ¦ÁÐ±í£©£¬¾Í¿ÉÒÔ¿´³ÉÊÇÒ»ÖÖµ¹ÅÅÐòË÷Òý¡£¿ÉÒÔͨ¹ýһЩ¹Ø¼ü×Ö£¬ÔÚÈ«ÊéÖмìË÷³öÓëÖ®Ïà¹ØµÄ²¿
Ë÷ÒýÎ ......