3 Replies Latest reply on Sep 14, 2007 10:45 AM by wayne baylor

    How to map this?

    Frank Langelage Master

      I'm migrating an EJB 2.1 application to EJB 3.0 using JBoss 4.2.2.GA.
      Some question on how to map fields and relations.
      Object message contains a message header, message parts and each message part contains message lines.
      message head has a generated id.
      message part has a composite pk build of message head id and part_no.

      public class Head implements Serializable
       private Integer headId;
       private Collection<Part> parts = new ArrayList<Part>();

      This gives me an Exception saying
      Repeated column in mapping for entity: Head column: head_id (should be mapped with insert="false" update="false").

      Is adding 'insert="false" update="false"' to the JoinColumn properties the right way to solve this duplicate field?
      What about using Transient?

      I get similar problems with ManyToOne relations.
      Database table for Order has a field order_type.
      This field is a FK to the OrderType table id.
      But order_type in combination with output_type is a composite FK to OrderProperties.
      So I would have in Order.java:
      - a field of type Integer named orderType
      - a field of type Integer named outputType
      - a ManyToOne relation to EB OrderType with JoinColumn orderType
      - a ManyToOne relation to EB OrderProperties with JoinColumns orderType and outputType
      So three mappings for column order_type and two mapping for column output_type.
      Should I omit the plain fields in this case and mark the JoinColumn orderType for OrderProperties with 'insert="false" update="false"' then?
      Or what's the best practice for something like this?