Uploaded image for project: 'Tools (JBoss Tools)'
  1. Tools (JBoss Tools)
  2. JBIDE-7568

Code generation for JPA 2.0 uses old features

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Obsolete
    • Icon: Major Major
    • 3.3.x
    • 3.2.0.Beta1
    • hibernate
    • None

      When choosing JPA 2.0 for code generation, then @OneToMany and @ManyToOne still generates relationships as in JPA 1.0. But the JPA 2.0 style is definitely better esspecially when it comes to unidirectional relationships where you just want to delete one side of the bidirectional relationship.

      Example: one customer has many orders

      @Entity
      @Table(name = "customer")
      public class Customer implements Serializable {
      ...
      @OneToMany
      @JoinColumn(name = "customer_fk") // foreign key in table "order"
      private Set<Order> orders;

      @Entity
      @Table(name = "order")
      public class Order implements Serializable {
      ...
      @ManyToOne
      @JoinColumn(name = "customer_fk", insertable = false, updatable = false)
      private Customer customer;

      As you can see: the foreign key is declared at both sides of the relationship so that one side can easily ommitted to just have a unidirectional relationship.

            manderse@redhat.com Max Andersen
            juergen.zimmermann Juergen Zimmermann
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: