Enhancement 351 : ENHANCEMENT - Add support for OneToMany JoinTables
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
github
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
26/01/2011
Updated 
26/01/2011
Type 
Enhancement
 
Attachments 
No attachments

Refer:
http://www.java2s.com/Tutorial/Java/0355__JPA/OneToManyJoinTableSetup.htm

Hi all,

On further investigation, I'm pretty sure that what I'm trying to do
is legit. It's a unidirectional oneToMany and I can see some examples
of using JPA to set it up:

http://www.java2s.com/Tutorial/Java/0355__JPA/OneToManyJoinTableSetup.htm
http://tadtech.blogspot.com/2007/09/hibernate-annotation-one-to-many-join.html

In Hibernate, for example, unidirectional appears to be the preferred
option.

I thought it might be that the Car had to specify all the details of
the join, so I tried this:


@OneToMany(cascade=CascadeType.ALL)
@PrivateOwned
@JoinTable(name="car_wheels",
joinColumns= {
@JoinColumn(name="car_id", referencedColumnName="id")
},
inverseJoinColumns = {
@JoinColumn(name="wheel_id", referencedColumnName="id")
}
)
private List wheels = new ArrayList();

...but I still get an exception:

java.lang.RuntimeException: Null Getter for: TestWheel.test_car
at
com.avaje.ebean.server.deploy.BeanProperty.(BeanProperty.java:
276)
at
com.avaje.ebean.server.deploy.BeanPropertyAssoc.(BeanPropertyAssoc.java:
93)
at
com.avaje.ebean.server.deploy.BeanPropertyAssocOne.(BeanPropertyAssocOne.java:
69)
at
com.avaje.ebean.server.deploy.meta.DeployBeanPropertyLists.(DeployBeanPropertyLists.java:
83)
at
com.avaje.ebean.server.deploy.BeanDescriptor.(BeanDescriptor.java:
425)
at
com.avaje.ebean.server.deploy.BeanDescriptorManager.readEntityRelationships(BeanDescriptorManager.java:
587)
at
com.avaje.ebean.server.deploy.BeanDescriptorManager.deploy(BeanDescriptorManager.java:
245)
at
com.avaje.ebean.server.core.InternalConfiguration.(InternalConfiguration.java:
134)
at
com.avaje.ebean.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:
168)
at
com.avaje.ebean.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:
104)
at
com.avaje.ebean.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:
67)
at com.avaje.ebean.EbeanServerFactory.create(EbeanServerFactory.java:
63)
at com.avaje.ebean.Ebean$ServerManager.getWithCreate(Ebean.java:226)
at com.avaje.ebean.Ebean$ServerManager.get(Ebean.java:213)
at com.avaje.ebean.Ebean$ServerManager.access$1(Ebean.java:203)
at com.avaje.ebean.Ebean.getServer(Ebean.java:277)


So... I'm starting to think this is a bug, or missing functionality in
Ebean? Or have I misunderstood? I'm using 2.3.

Thanks,
Alastair

 
Saulius 05 Jul 15:10
Same problem here

I've run into exactly the same problem. It seems Ebean does not interpret @JoinTable right.

I have entities:

@Entity
@Table(name = "hotel_room")
public class HotelRoom {

....(id and version)....

@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "offsite_hotel_room_pax", joinColumns = @JoinColumn(name="room"), inverseJoinColumns = @JoinColumn(name = "passenger"))
private List pax;

....(getters and setters)....
}

@Entity
@Table(name = "passenger")
public class Passenger {

....(id and version)....

protected String firstname;

protected String lastname;

....(getters and setters)....
}

Whenever I select hotel room:

HotelRoom room = Ebean.find(OffsiteHotelRoom.class, 31841804);

I get error:

javax.persistence.PersistenceException: Query threw SQLException:ERROR: column t1.room does not exist
Bind values:[31841804]
Query was:
select t0.id as c0, t1.id as c1, t1.firstname as c2, t1.lastname as c3, t1.version as c4
from offsite_hotel_room t0
left outer join passenger t1 on t1.room = t0.id
where t0.id = ?
order by t0.id


at com.avaje.ebeaninternal.server.query.CQuery.createPersistenceException(CQuery.java:849)
at com.avaje.ebeaninternal.server.query.CQuery.createPersistenceException(CQuery.java:829)
at com.avaje.ebeaninternal.server.query.CQueryEngine.findMany(CQueryEngine.java:238)
at com.avaje.ebeaninternal.server.query.DefaultOrmQueryEngine.findMany(DefaultOrmQueryEngine.java:104)
at com.avaje.ebeaninternal.server.core.OrmQueryRequest.findList(OrmQueryRequest.java:344)
at com.avaje.ebeaninternal.server.core.DefaultServer.findList(DefaultServer.java:1469)
at com.avaje.ebeaninternal.server.core.DefaultBeanLoader.loadMany(DefaultBeanLoader.java:162)
at com.avaje.ebeaninternal.server.core.DefaultServer.loadMany(DefaultServer.java:511)
at com.avaje.ebeaninternal.server.loadcontext.DLoadManyContext.loadMany(DLoadManyContext.java:142)
at com.avaje.ebean.common.AbstractBeanCollection.lazyLoadCollection(AbstractBeanCollection.java:153)
at com.avaje.ebean.common.BeanList.init(BeanList.java:116)
at com.avaje.ebean.common.BeanList.size(BeanList.java:410)
at lt.travelonline.Utils.getCollectionSize(Utils.java:1448)
at lt.travelonline.Utils.getSize(Utils.java:1513)
at lt.travelonline.test.EbeanTest.testJoinTable(EbeanTest.java:136)

Bence 08 Aug 08:17
vote

+1

woResponse

Upload a file