-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: org.hibernate.MappingException with Embedded NaturalId
PostPosted: Wed Nov 16, 2016 9:26 am 
Newbie

Joined: Wed Nov 16, 2016 8:40 am
Posts: 5
I use hibernate 5.2.4.
When I try to use @NaturalId with @Embedded, there is an exception
(org.hibernate.MappingException: Unable to find column with physical name ...).
If I use @Embedded without @NaturalId all work fine

My code:
Code:
package com.slavick.hibernate.example;
import org.hibernate.annotations.NaturalId;
import javax.persistence.*;

@Entity
@Access(AccessType.FIELD)
public class Bar {
   
@Id
    @GeneratedValue
    long id;

    @NaturalId
    @Embedded
    Foo foo;

    public Bar(){};

}

package com.slavick.hibernate.example;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Embeddable;

@Embeddable
@Access(AccessType.FIELD)
public class Foo {
    @Column(name = "str")
    String string;

    public Foo(){}
}

package com.slavick.hibernate.example;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import java.util.Properties;


public class Program {
    public static void main(String[] args) {

        Properties prop = new Properties();
        prop.setProperty("hibernate.connection.url", "jdbc:mysql://192.168.72.130:3306/test2");
        prop.setProperty("hibernate.connection.username", "user");
        prop.setProperty("hibernate.connection.password", "user");
        prop.setProperty("dialect", "org.hibernate.dialect.MySQLDialect");
        prop.setProperty("hibernate.hbm2ddl.auto", "create-drop");
        prop.setProperty("hibernate.show_sql", "true");
        prop.setProperty("jdbc.driverClassName", "com.mysql.jdbc.Driver");

        Configuration configuration = new Configuration().addProperties(prop).
addAnnotatedClass(Foo.class).addAnnotatedClass(Bar.class);


        StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
        serviceRegistryBuilder.applySettings(configuration.getProperties());
        ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
        SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);

        Session session = sessionFactory.openSession();

        Foo foo = new Foo();
        foo.string="string";
        Bar bar = new Bar();
        bar.foo=foo;

        session.persist(bar);

        session.close();
        sessionFactory.close();
        StandardServiceRegistryBuilder.destroy(serviceRegistry);

    }
}




STDOUT:
Quote:
"C:\Program Files (x86)\Java\jdk1.8.0_91\bin\java" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:9989,suspend=y,server=n -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\charsets.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\deploy.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\ext\access-bridge-32.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\ext\cldrdata.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\ext\dnsns.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\ext\jaccess.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\ext\jfxrt.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\ext\localedata.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\ext\nashorn.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\ext\sunec.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\ext\sunjce_provider.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\ext\sunmscapi.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\ext\sunpkcs11.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\ext\zipfs.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\javaws.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\jce.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\jfr.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\jfxswt.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\jsse.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\management-agent.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\plugin.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\resources.jar;C:\Program Files (x86)\Java\jdk1.8.0_91\jre\lib\rt.jar;C:\Users\apanasyonok\Downloads\HibernateExample\target\classes;C:\Users\apanasyonok\.m2\repository\mysql\mysql-connector-java\5.1.31\mysql-connector-java-5.1.31.jar;C:\Users\apanasyonok\.m2\repository\org\hibernate\hibernate-core\5.2.4.Final\hibernate-core-5.2.4.Final.jar;C:\Users\apanasyonok\.m2\repository\org\jboss\logging\jboss-logging\3.3.0.Final\jboss-logging-3.3.0.Final.jar;C:\Users\apanasyonok\.m2\repository\org\hibernate\javax\persistence\hibernate-jpa-2.1-api\1.0.0.Final\hibernate-jpa-2.1-api-1.0.0.Final.jar;C:\Users\apanasyonok\.m2\repository\org\javassist\javassist\3.20.0-GA\javassist-3.20.0-GA.jar;C:\Users\apanasyonok\.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;C:\Users\apanasyonok\.m2\repository\org\apache\geronimo\specs\geronimo-jta_1.1_spec\1.1.1\geronimo-jta_1.1_spec-1.1.1.jar;C:\Users\apanasyonok\.m2\repository\org\jboss\jandex\2.0.0.Final\jandex-2.0.0.Final.jar;C:\Users\apanasyonok\.m2\repository\com\fasterxml\classmate\1.3.0\classmate-1.3.0.jar;C:\Users\apanasyonok\.m2\repository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar;C:\Users\apanasyonok\.m2\repository\org\hibernate\common\hibernate-commons-annotations\5.0.1.Final\hibernate-commons-annotations-5.0.1.Final.jar;C:\Users\apanasyonok\.m2\repository\javax\enterprise\cdi-api\1.1\cdi-api-1.1.jar;C:\Users\apanasyonok\.m2\repository\javax\el\el-api\2.2\el-api-2.2.jar;C:\Users\apanasyonok\.m2\repository\org\jboss\spec\javax\interceptor\jboss-interceptors-api_1.1_spec\1.0.0.Beta1\jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar;C:\Users\apanasyonok\.m2\repository\javax\annotation\jsr250-api\1.0\jsr250-api-1.0.jar;C:\Users\apanasyonok\.m2\repository\javax\inject\javax.inject\1\javax.inject-1.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.2.5\lib\idea_rt.jar" com.slavick.hibernate.example.Program
Connected to the target VM, address: '127.0.0.1:9989', transport: 'socket'
но. 16, 2016 4:07:31 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.4.Final}
но. 16, 2016 4:07:31 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
но. 16, 2016 4:07:31 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
но. 16, 2016 4:07:31 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
но. 16, 2016 4:07:31 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
но. 16, 2016 4:07:31 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [null] at URL [jdbc:mysql://192.168.72.130:3306/test2]
но. 16, 2016 4:07:31 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=user, password=****}
но. 16, 2016 4:07:31 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
но. 16, 2016 4:07:31 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
но. 16, 2016 4:07:31 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Exception in thread "main" org.hibernate.MappingException: Unable to find column with physical name foo in table Bar
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.getLogicalColumnName(InFlightMetadataCollectorImpl.java:1001)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.getLogicalColumnName(InFlightMetadataCollectorImpl.java:971)
at org.hibernate.cfg.IndexOrUniqueKeySecondPass.doSecondPass(IndexOrUniqueKeySecondPass.java:69)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1621)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1589)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
at com.slavick.hibernate.example.Program.main(Program.java:32)


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException with Embedded NaturalId
PostPosted: Wed Nov 16, 2016 12:26 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I tried to replicate it and indeed we have an issue.

I created the HHH-11255 Jira ticket for this issue.


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException with Embedded NaturalId
PostPosted: Thu Nov 17, 2016 11:25 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I fixed the issue: HHH-11255. I will be available in Hibernate 5.2.5 once we release it.

Thanks for reporting it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.