[jboss-user] [EJB 3.0] - Re: Generate ID when creating entities

tcupp1 do-not-reply at jboss.com
Tue Jan 29 09:25:45 EST 2008


Use Hibernate annotations and generated values. This is a very quick example, and may not work out of the box.



  | public class Parent {
  | 
  | @Id
  | @GeneratedValue(strategy = GenerationType.SEQUENCE)
  | private Long id
  | 
  | @OneToOne
  | @PrimaryKeyJoinColumn
  | private Child child;
  | }
  | 
  | public class Child {
  | 
  | @Id
  | @GeneratedValue(generator="foreignKeyGenerator")
  | @org.hibernate.annotations.GenericGenerator(name="foreignKeyGenerator", strategy="foreign",parameters=@Parameter(name="property", value="parent"))
  | 
  | @OneToOne(optional=false)
  | @JoinColumn(name="id")
  | private Parent parent;
  | }
  | 

HTH

Tim

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4124420#4124420

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4124420



More information about the jboss-user mailing list