Is @SecondaryTable implemented in Ebean?

231 views
Skip to first unread message

Joseph Conley

unread,
Jan 8, 2012, 1:27:11 PM1/8/12
to eb...@googlegroups.com
Hello, I am trying to implement a very basic @SecondaryTable example but continually run into the same error.  Here's the example:

@Entity
@SecondaryTable(name = "asset_ext", pkJoinColumns = @PrimaryKeyJoinColumn(name = "asset_id"))
public class Asset {
@Id
public int id;
public String name;
public Date dateSaved;
public byte[] file;
@Column(table="asset_ext")
public String extId;
public Asset(String name, byte[] file){
this.name = name;
this.file = file;
this.dateSaved = new Date();
}

//getters and setters
}

And here's the error I keep getting:

Error with property Asset.extId. Could not find a Relationship to table asset_ext. Perhaps you could use a @JoinColumn instead.

The tables are well-defined with the proper primary/foreign key constraints (in a mysql db).  I've tried mucking around in the source code but haven't figured it out yet.  Does Ebean even support the @SecondaryTable annotation?  Thanks.

Rob Bygrave

unread,
Jan 8, 2012, 3:05:05 PM1/8/12
to eb...@googlegroups.com
Yes, it supports @SecondaryTable (but I'd suggest it is fairly rarely used due to partial object support).

The issue might be around @PrimaryKeyJoinColumn. You could use @JoinColumn to define the join - is there a reason you are not wanting to do that?

Joseph Conley

unread,
Jan 8, 2012, 8:12:28 PM1/8/12
to eb...@googlegroups.com
I had only used the @JoinColumn annotation for joining entities, not properties.  As I could have several properties in my extension table that could require joining I thought the @SecondaryTable approach was better suited.  Can you describe how I would use @JoinColumn in my example above?

In addition, I'm taking the @SecondaryTable approach as a workaround to not having the JOINED inheritance strategy implemented.  My example doesn't touch on that but I actually have an asset table with two separate extension tables, asset_ext and asset_int.  So ideally, I would use joined inheritance to create an abstract Asset class with two child tables.  Do you recommend a workaround for this situation in Ebean?  

This has been my only hiccup so far, I'm quite impressed otherwise with Ebean and hope to use it on my upcoming project.  Thanks for your help!

Joseph Conley

unread,
Jan 17, 2012, 12:40:31 PM1/17/12
to eb...@googlegroups.com
FYI my current workaround is to use a BeanAdapter to handle CRUD operations on the extension tables.  I'd be curious to learn about other workarounds to joined inheritance, however.

Leon Hall

unread,
Mar 6, 2012, 11:16:53 AM3/6/12
to Ebean ORM
I am also looking for a workaround for not having JOINED Inheritance.
Any more thoughts on this topic. Can you provide a bit more detail
about you BeanAdapter approach?

Rob Bygrave

unread,
Mar 6, 2012, 3:24:35 PM3/6/12
to eb...@googlegroups.com
Yes you can use @SecondaryTable. What is you question about BeanAdapter?

Minh Pham

unread,
Jul 20, 2017, 7:17:21 PM7/20/17
to Ebean ORM
I'm sorry to revive such an old thread, but as of Ebean ORM 6.13.3, this exact issue persists with H2 database.

This thread is the only place where this issue is documented, but please let me know if I should open a new thread.

Rob Bygrave

unread,
Jul 21, 2017, 9:08:31 PM7/21/17
to ebean@googlegroups
It is not clear what your question is so you need to post it again as clearly as you can.

Thanks, Rob.

--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Minh Pham

unread,
Jul 25, 2017, 4:57:37 PM7/25/17
to Ebean ORM
As of 6.13.3, @SecondaryTable doesn't seem to work.

The error I receive is something like this:

Error with property <prop_name>. Could not find a Relationship to table <secondary_table>. Perhaps you could use a @JoinColumn instead.

Please let me know if you need me to provide a test case.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages