[jboss-user] [EJB 3.0] - How to map this?
lafr
do-not-reply at jboss.com
Tue Sep 11 17:19:50 EDT 2007
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.
@Entity
| @Table(name="head")
| public class Head implements Serializable
| {
| @Id
| @GeneratedValue(strategy=GenerationType.IDENTITY)
| @Column(name="head_id")
| private Integer headId;
|
| @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
| @OrderBy("partNo")
| @JoinColumns({
| @JoinColumn(name="head_id",referencedColumnName="head_id")
| })
| 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?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4083184#4083184
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4083184
More information about the jboss-user
mailing list