JavaEE5 实战笔记02 JPA 持久层的一些问题


1 / 8 JavaEE5  02JPA ฆጱ  Email:suhuanzheng7784877@163.com 1. JPA   ¡ ¢ £ ¤ ¥ ¡¦ § ¨ © ¡      ¤    ¢ £    ¡     ¤ ¦ §     !" # $ %& ¢ £  ¦ §     ¢ £ '  ()   ¡*  ¢ £ + , -.   ¤/ 0  ¦ §     1 2 3  4 ¤ 1 56 ¤ 78 & ¥ ¡- . ¤+ 9 ¦ §   '  : -. ¤ ¦ §    4 ;;  <   = ¦ §  >  ? @ & +A :B    C   ¢ £ D EF  ¦ §      ¦ §   D E   ¦ §     ¢ £ # GH D E     ¢ £    ¦ §     ¢ £ D E   ¦ §   + ¢ £ Bean IJ K L   ¢ £ C UserDTO package ejb.dto; import java.io.Serializable; import java.sql.Timestamp; import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; import org.hibernate.annotations.GenericGenerator; /** *   ¢ £ * * @author liuyan 2 / 8 */ @Entity @Table(name = "webbank_user") public class UserDTO implements Serializable { private static final long serialVersionUID = 1L; public UserDTO() { } @Id @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") // A M private String id; @Column(name = "userName") //  N private String userName; @Column(name = "password") // O J private String password; @Column(name = "userStates") //  P Q private int userStates; @Column(name = "money") //  R S private double money; @Column(name = "registeTime") // T U /V private Timestamp registeTime; @OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY, mappedBy = 3 / 8 "userDTO") private List deals; // WX setter Y getter } ¦ §   ¢ £ C DealDTO package ejb.dto; import java.io.Serializable; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToOne; import javax.persistence.Table; import org.hibernate.annotations.GenericGenerator; /** * Z[ \] ^ _ * @author liuyan */ @Entity @Table (name = "webbank_deal" ) public class DealDTO implements Serializable { public DealDTO(){ } private static final long serialVersionUID = 4210820165040311694L; @Id @GeneratedValue (generator= "system-uuid" ) @GenericGenerator (name= "system-uuid" ,strategy = "uuid" ) private String id ; @ManyToOne (optional = true , cascade = CascadeType. REFRESH) @JoinColumn (name = "user_ID" ) 4 / 8 private UserDTO userDTO ; @OneToOne (optional = true , cascade = CascadeType. ALL) @JoinColumn (name = "dealInfo_ID" ) private DealInfoDTO dealInfoDTO ; // WX setter Y getter } ¦ §     ¢ £ : DealInfoDTO package ejb.dto; import java.io.Serializable; import java.sql.Timestamp; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToOne; import javax.persistence.Table; import org.hibernate.annotations.GenericGenerator; /** * Z[ ` a ^ _ * @author liuyan */ @Entity @Table (name = "webbank_dealInfo" ) public class DealInfoDTO implements Serializable { public DealInfoDTO(){ } private static final long serialVersionUID = -2266758318775332821L; @Id 5 / 8 @GeneratedValue (generator= "system-uuid" ) @GenericGenerator (name= "system-uuid" ,strategy = "uuid" ) private String id ; @Column (name = "dealDate" ) private Timestamp dealDate ; @Column (name = "dealStatue" ) private int dealStatue ; @Column (name = "dealMessage" ) private String dealMessage ; @OneToOne (optional = true , cascade = CascadeType. ALL) private DealDTO dealDTO ; // WX setter Y getter } UserDTO ¢ £  ¤ b  C @OneToMany (cascade = CascadeType. REMOVE, fetch = FetchType. LAZY, mappedBy = "userDTO" ) private List deals ; cde f g hi j k ¤ l m  C n K o JPA E UserDTO ¢ £pq r ¦ §  s t uv ¤ ¦ §  K ow x y r -. UserDTO ¢ £ ¤ l  ' : < UserDTO ¢ £ v   ¤ DealDTO ¢ £  G # ¥ ¡ z # {| } ~ z # € ‚ z -. ƒ „ ; n …†   ¢ £ ¤‡ /' … †¦ §   ¢ £ ˆ ‰  € Š  ‹Œ …† „ ; n F¤   ŽŽ DealDTO ¢ £ v    ‘ 2 ’   ¤  +' m “”F¤ s    • 1VSN ¤   – r + „ DealDTO ¢ £  ¤ b  C @ManyToOne (optional = true , cascade = CascadeType. REFRESH) @JoinColumn (name = "user_ID" ) private UserDTO userDTO ; — h l ˜“ m  C n   ¢ £ = ¦ §   ¢ £   ¦ § ¢ £§ ™F¤   N  š  › ¦§   E œ ž v   = 3 E Ÿ ¤     „   n , E ¦§   ¢ £ p q ¡ ¢¦§ ¤ / 6 / 8 0  £Ÿ ¤  ¥ ¤ ¥  E  ¢ £ ' : p q¥ ¡ ¤ ¡¢ „   ¦   : “  ¤ m  F¤   ‘ r 1VSN ¤    § ¨© ª«  ‘ ¤ m  user_ID + ¢ £ ¤ ¦  b  @OneToOne (optional = true , cascade = CascadeType. ALL) @JoinColumn (name = "dealInfo_ID" ) private DealInfoDTO dealInfoDTO ; f g ' ˜  — h l “ m  C n E DealDTO ¢ £ ¤¬ ­ ¦ § ®  ¯ °* ¦ §  ¢ £ DealInfoDTO ¤ ± ¥P Q + ² ¥ DealDTO ¢ £  ³ ´  µ £ Ÿ ¤   ¢ £ ' ¶·¸ ¹ ² ¥ ¤ º » + -. DealDTO ¢ £  | ¼ *   ¢ £ ' ½ ¾ ¿ À Á „   n ‡ /  DealDTO ¢ £ ‘ *  ¹ 1VS1 ¤   ¤   + „ DealInfoDTO ¢ £  ¤ b  C @OneToOne (optional = true , cascade = CascadeType. ALL) private DealDTO dealDTO ;  m à ÄÅ Æ r ~~   ¤ uv¦ § ® ¯ ° * DealDTO ¢ £  . 3 ÇÈ ³ ¤ 7 8 + , É r DealDTO ¢ £ = DealInfoDTO ¢ £  ( ÊË £®€1 ™ Ì + (Ê m Í Î Š YÏ ÐÑ    Ò ‡ pÓ # K ÔÕ Ò# Ö' × € r Ö# ØÙ Ú' €1 Û± # ØÜ Ý 16 Þ  Ú m ß Ø 16 Þ Á à á â ã ¤ JPA ä å m 1 æ ç è é ¤   p q ¢ £ ¤ ¦ § r + 2. UUID ¤A M± e ê ë   ¤  Oracle10g © ª «   ì ¤ Oracle  h Ší î p q A M ¤ ± e ¤ ê ë   4 ï ð  ¹ Êñ m  ò  UUID ¤ Êñ p q A M± e + ¢ £ Tó  … ô @Id @GeneratedValue (generator = "system-uuid" ) @GenericGenerator (name = "system-uuid" , strategy = "uuid" ) private String id ; 7 / 8 õ  ö  UUID ± e A M  GH m  ¢÷ ²¥ ¢ £ ¤/ 0 ø ù € :   ± e A M  § ¨ ¤ Hibernate úû ü ý ™ Ø > r A M ¤ ± e Y þ% ÿ § + 3.   ¡ €  : ¢ £¤¥ ¤     K L  à K   ! " ¤ Š ¦  § ± r ¨ ©  s t  :   y    +  4 ¥  ¨ ©  » y ! " § ± À q / ¨ © ¤ Š ¦  : ¢ £    s t ¢ £ ¤   ¦ § m €1 =!"  £ Ò· ‡  ¢ £  , » y  q ² ¥ ¢ £ ¤/ 0  : ¦    ¢ ¤ ¢ £ + ¨ © ¢ £  ¤ Service ¨ ¤ IJK L @Stateless @TransactionManagement (TransactionManagementType. CONTAINER) @TransactionAttribute (TransactionAttributeType. REQUIRES_NEW) public class ExceptionLogServiceImpl extends BaseServiceImpl implements ExceptionLogService { /** *     EJB   */ @EJB(beanName = "ExceptionLogEAOImpl" ) private ExceptionLogEAO exceptionLogEAO ; public ExceptionLogServiceImpl() { super (); System. out .println( "ExceptionLogServiceImpl    "); } } REQUIRES_NEW I ¦     ¢ ¤ ¢ !  " £ ¤ ¢ £ ¤ ¥ # $ % & ' C http://suhuanzheng7784877.iteye.com/blog/908382 1.Required C Ò· ( ) 1 *   ¢ £  +  r 2  , 2 - . Y 1 ‡  ¢ £  + ) 1 È v ¬­ ¢ £  , /  01 2 2 34   ¢ ¢ £ + ê ë 5 ‰ 6 F © ‚ 7 + 8 / 8 2.RequiredNew C Û 8 ( ) 1   ¢ £  +  r 2  , / è < 1 ¤ ¢ £9 :  € ; # 3 < ™ 2 = å   ¢ ¢ £   q > ? < @A 1 ¤ ¢ £ + ) 1 Èv ¢ £  ,  ™ 2 ¢    ¢ £ + 3.Mandatory C BC Ò· ( ) 1 *   ¢ £  +  r 2  , 2 - . Y 1 ‡  ¢ £  + ) 1 È v ¬­ ¢ £  - . DE ¨ © ——Transaction RequiredException + 4.NotSupported C F G Û 8 ( ) 1   ¢ £  +  r 2  , / è < 1 ¤ ¢ £9 :  € ; # 3 < 2 €  H ¬­ ¢ £   q > ? <@ A 1 ¤ ¢ £ + ) 1 Èv ¢ £  2 ' - .  q + 5. Supported C I J( ) 1 *   ¢ £  +  r 2  , 2 - . Y 1 ‡  ¢ £  + ) 1 È v ¬­ ¢ £  - .  q 2 + 6.Never C K L( ) 1 *   ¢ £  +  r 2  ,D E RemoteException + ) 1 È v ¬­ ¢ £  - .  q 2 ' €  ™ µ  H ¬­ ¢ £ +
还剩7页未读

继续阅读

下载pdf到电脑,查找使用更方便

pdf的实际排版效果,会与网站的显示效果略有不同!!

需要 3 金币 [ 分享pdf获得金币 ] 0 人已下载

下载pdf

pdf贡献者

zhyp29

贡献于2014-05-25

下载需要 3 金币 [金币充值 ]
亲,您也可以通过 分享原创pdf 来获得金币奖励!
下载pdf