1

Abridged version of my schema:

utility_company
id int not null -- PK
name varchar(255) not null

utility_settings
utility_id -- FK to utility
use_magic tinyint(1) not null default 0

There is a one-to-one mapping between these two tables. Setting aside the fitness of this design, I want to Map the data in both of these tables to one object. In Hibernate/JPA, this is allegedly done as follows:

@Entity
@Table(name = "utility_company")
@SecondaryTables({
    @SecondaryTable(
        name = "utility_settings", 
        pkJoinColumns = {
            @PrimaryKeyJoinColumn(
                name="utility_id", referencedColumnName="id")
        })
})
public class UtilityCompany extends AbstractEntity {

And so forth.

Every @Column includes the appropriate table name.

When I deploy, I get this error:

Cannot find the expected secondary table: 
no utility_company available for poscore.model.UtilityCompany

The utility_company table is definitely there (a previous version only maps UtilityCompany to the utility_company table; I'm adding the utility_settings).

Found numerous forum posts with this exact problems and no answers. I've also tried various allegedly legal forms of specifying the @SecondaryTable all of which have the same effect.

Anyone successfully use @SecondaryTable, and, if so, seen this?

1
  • I know this question is very old, but... I have the same problem. Have you solved it? Commented May 3, 2012 at 8:58

2 Answers 2

3

"Every @Column includes the appropriate table name."

Try removing the explicit table name for the first table name columns, only specifying it for the secondary table columns. Did the trick for me.

Sign up to request clarification or add additional context in comments.

Comments

1

Your mappings are correct IMHO, and runs fine with DataNucleus AccessPlatform as the JPA implementation. Maybe Hibernates log tells you more ?

--Andy DataNucleus

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.