views:

959

answers:

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?

A: 

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

--Andy DataNucleus

DataNucleus