• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OneToMany Unidirectional strange behavior ?

 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am implementing hibernate with JPA annotations and trying to do a very simple thing but seeing very different behavior in oracleAS.

I have an Order object which has many OrderLineItems and i want a unidirectional relationship NOT A BIDIRECTIONAL.

When i try the following code with a main method, it does work perfectly fine, but the same code when deploying to Oracle Application server in a session bean it fails with the following exception

Exception Description: @OneToMany for attribute name [orderLineItemsList] in entity class [class com.thoughtclicks.domains.Orders] should not have @JoinColumn(s) specified. In the case where the @OneToMany is not mapped by another entity (that is, it is the owning side and is uni-directional), it should specify (optional through defaulting) a @JoinTable.

Below is the defination of Order Object: and as it is unidirection there is no code for order in orderlineitems

@OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
@JoinColumn(name="ORD_ID")
public List<OrderLineItems> getOrderLineItemsList() {
return orderLineItemsList;
}

Does anybody know what can be the issue with the oracle as deployment ?

Message was edited by:
rahul_juneja
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look here...
JSR220


2.1.8.5.1 Unidirectional OneToMany Relationships
The following mapping defaults apply:
Entity A is mapped to a table named A.
Entity B is mapped to a table named B.
There is a join table that is named A_B (owner name first). This join table has two foreign key
columns. One foreign key column refers to table A and has the same type as the primary key of
table A. The name of this foreign key column is formed as the concatenation of the following:
the name of entity A; "_"; the name of the primary key column in table A. The other foreign
key column refers to table B and has the same type as the primary key of table B and there is a
unique key constraint on it. The name of this foreign key column is formed as the concatenation
of the following: the name of the relationship property or field of entity A; "_"; the name
of the primary key column in table B.
Example:
@Entity
public class Employee {
private Collection<AnnualReview> annualReviews;
@OneToMany
public Collection<AnnualReview> getAnnualReviews() {
return annualReviews;
}
public void setAnnualReviews(Collection<AnnualReview> annualReviews)
{
this.annualReviews = annualReviews;
}
...
}
@Entity
public class AnnualReview {
...
}
In this example:
Requirements on the Entity Class Enterprise JavaBeans 3.0, Final Release Entities
33 5/2/06
Sun Microsystems, Inc.
Entity Employee references a collection of Entity AnnualReview.
Entity AnnualReview does not reference Entity Employee.
Entity Employee is the owner of the relationship.
The following mapping defaults apply:
Entity Employee is mapped to a table named EMPLOYEE.
Entity AnnualReview is mapped to a table named ANNUALREVIEW.
There is a join table that is named EMPLOYEE_ANNUALREVIEW (owner name first). This
join table has two foreign key columns. One foreign key column refers to table EMPLOYEE
and has the same type as the primary key of EMPLOYEE. This foreign key column is named
EMPLOYEE_<PK of EMPLOYEE>, where <PK of EMPLOYEE> denotes the name of the primary
key column of table EMPLOYEE. The other foreign key column refers to table ANNUALREVIEW
and has the same type as the primary key of ANNUALREVIEW. This foreign key
column is named ANNUALREVIEWS_<PK of ANNUALREVIEW>, where <PK of ANNUALREVIEW>
denotes the name of the primary key column of table ANNUALREVIEW. There
is a unique key constraint on the foreign key that refers to table ANNUALREVIEW.
 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But I tried deploying the same on jboss and it went through.

Thanks,
Rahul
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reference, that helps to explain why I'm having similar issues.

I'm somewhat new to EJB. Do you have any idea why the EJB standards seek to dictate database design by forcing the user to create 3 tables to model a One to Many relationship instead of the standard 2 with a foreign key to a primary key? In the past, I have used 3 tables only to model ManyToMany relationships.

BEGIN QUOTE

2.1.8.5.1 Unidirectional OneToMany Relationships
...
2.1.8.5.1 Unidirectional OneToMany Relationships
The following mapping defaults apply:
Entity A is mapped to a table named A.
Entity B is mapped to a table named B.
There is a join table that is named A_B (owner name first). This join table has two foreign key columns. One foreign key column refers to table A and has the same type as the primary key of table A. The name of this foreign key column is formed as the concatenation of the following:
the name of entity A; "_"; the name of the primary key column in table A. The other foreign
key column refers to table B and has the same type as the primary key of table B and there is a
unique key constraint on it. The name of this foreign key column is formed as the concatenation
of the following: the name of the relationship

ENDQUOTE
reply
    Bookmark Topic Watch Topic
  • New Topic