3

I am having a hard time trying to find an error related to columns mapping with Hibernate. I am storing on a SQL the information of several applications, each of them may have or not one or more addins. The relation between the application and addins is resolved without issues. However there is as second relation that are the addin with several properties that they may have. I am just adding the objects where I get the error below

@Embeddable
public class PropertyKey implements Serializable
{
    /**
     * 
     */
    private static final long serialVersionUID = -7240987531179265668L;
    private String strObjectGUID;
    private String strValue;
}
@Entity
@Table(name = "tbl_properties")
public class PropertyEntity
{
    @EmbeddedId
    private PropertyKey objKey;
}
@Entity
@Table(name = "tbl_addins")
public class AddInEntity
{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "intCode")
    private Integer intCode;
    private String strID;
    private String strApplicationID;
    private String strType;
    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = "strObjectGUID", referencedColumnName = "strPropertyID")
    private List<PropertyEntity> colProperties;
}

The error that I receive is:

[main] INFO com.mchange.v2.c3p0.C3P0Registry - Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
[main] INFO com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@b781de3a [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@ed59c9fa [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, identityToken -> 2ssjxha01fbizdoddf7pr|38eb2c50, idleConnectionTestPeriod -> 3000, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 300, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 1000, maxStatements -> 1000, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@4c881e72 [ description -> null, driverClass -> null, factoryClassLocation -> null, forceUseNamedDriverClass -> false, identityToken -> 2ssjxha01fbizdoddf7pr|5411dd90, jdbcUrl -> jdbc:sqlserver://localhost, properties -> {databasename=Azure, integratedsecurity=true} ], preferredTestQuery -> null, privilegeSpawnedThreads -> false, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, extensions -> {}, factoryClassLocation -> null, identityToken -> 2ssjxha01fbizdoddf7pr|23202c31, numHelperThreads -> 3 ]
Initial SessionFactory creation failed.org.hibernate.AnnotationException: Unable to map collection azure.entities.AddInEntity.colProperties
Monday, 4 Feb 2019 11:42:46 AM [main] ERROR azure.hibernate.HibernateUtil - Initial SessionFactory creation failed
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: org.hibernate.AnnotationException: Unable to map collection azure.entities.AddInEntity.colProperties
Caused by: org.hibernate.cfg.RecoverableException: Unable to find column with logical name: strPropertyID in org.hibernate.mapping.Table(tbl_addins) and its related supertables and secondary tables
Caused by: org.hibernate.MappingException: Unable to find column with logical name: strPropertyID in org.hibernate.mapping.Table(tbl_addins) and its related supertables and secondary tables

The SQL schema for this objects are:

CREATE TABLE tbl_properties
(
    strObjectGUID nvarchar(36) NOT NULL,
    strValue nvarchar(MAX)
    CONSTRAINT pk_properties PRIMARY KEY (strObjectGUID)
)
CREATE TABLE tbl_addins
(
    intCode int NOT NULL IDENTITY(1, 1),
    strID nvarchar(36) NOT NULL,
    strApplicationID nvarchar(36) NOT NULL,
    strType nvarchar(MAX),
    strPropertyID nvarchar(36)
    CONSTRAINT pk_addins PRIMARY KEY (intCode),
    CONSTRAINT fk_addins_properties FOREIGN KEY (strPropertyID) REFERENCES tbl_properties(strObjectGUID),
    CONSTRAINT fk_addins_applications FOREIGN KEY (strApplicationID) REFERENCES tbl_applications(strObjectGUID)
)

I have tried changing the combinedkey by an Identifier on PropertyEntity, but the same error occurs Do you have any idea of what can be happening. Should I declare the Join in a different way?

1
  • And what's the reason for using @EmbeddedId here? according to the sql - you have only one primary key for tbl_properties. Doesn't look like a case for Embedded using. Commented Feb 5, 2019 at 10:05

2 Answers 2

1

Fixed using mappedBy annotation. @OneToMany(cascade = CascadeType.ALL, mappedby = "objKey.strObjectGUID")

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

Comments

-1

According to @JoinColumn documentation

name is used for column of the current table referencedColumnName is used to set column of the joined table.

In your case you need to replace config with:

@JoinColumn(name = "strPropertyID", referencedColumnName = "strObjectGUID")

1 Comment

same error, it just change the column name: Unable to find column with logical name: strObjectGUID in org.hibernate.mapping.Table(tbl_addins)

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.