Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hhh 6039 Bug fix related to CriteriaQuery (JPA) when using XML mappings #276

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java
Expand Up @@ -452,6 +452,7 @@ private static void bindSimpleId(Element idNode, RootClass entity, Mappings mapp
prop.setValue( id );
bindProperty( idNode, prop, mappings, inheritedMetas );
entity.setIdentifierProperty( prop );
entity.setDeclaredIdentifierProperty( prop );
}

// TODO:
Expand Down Expand Up @@ -485,6 +486,7 @@ private static void bindCompositeId(Element idNode, RootClass entity, Mappings m
prop.setValue( id );
bindProperty( idNode, prop, mappings, inheritedMetas );
entity.setIdentifierProperty( prop );
entity.setDeclaredIdentifierProperty( prop );
}

makeIdentifier( idNode, id, mappings );
Expand Down Expand Up @@ -569,6 +571,7 @@ public static void bindClass(Element node, PersistentClass persistentClass, Mapp
throw new MappingException( "Unable to determine entity name" );
}
persistentClass.setEntityName( entityName );
persistentClass.setJpaEntityName( entityName );

bindPojoRepresentation( node, persistentClass, mappings, inheritedMetas );
bindDom4jRepresentation( node, persistentClass, mappings, inheritedMetas );
Expand Down
@@ -0,0 +1,35 @@
package org.hibernate.ejb.test.xml;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import org.junit.Test;

import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;

/**
* @author Strong Liu <stliu@hibernate.org>
*/
@TestForIssue( jiraKey = "HHH-6039, HHH-6100" )
public class JpaEntityNameTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected String[] getMappings() {
return new String[]{"org/hibernate/ejb/test/xml/Qualifier.hbm.xml"};
}
@Test
public void testUsingSimpleHbmInJpa(){
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Qualifier> cq = cb.createQuery(Qualifier.class);
Root<Qualifier> qualifRoot = cq.from(Qualifier.class);
cq.where( cb.equal( qualifRoot.get( "qualifierId" ), 32l ) );
em.createQuery(cq).getResultList();
em.getTransaction().commit();
em.close();
}
}
@@ -0,0 +1,34 @@
package org.hibernate.ejb.test.xml;

/**
* @author Strong Liu <stliu@hibernate.org>
*/
public class Qualifier {
private Long qualifierId;
private String name;
private String value;

public Long getQualifierId() {
return qualifierId;
}

public void setQualifierId(Long qualifierId) {
this.qualifierId = qualifierId;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<!--

-->

<hibernate-mapping package="org.hibernate.ejb.test.xml">

<class name="Qualifier" table="QUALIFIER">
<id name="qualifierId" column="QUALIFIER_ID" type="long">
<generator class="native"/>
</id>
<property name="name" type="string">
<column name="NAME" length="20" not-null="true"/>
</property>
<property name="value" type="string">
<column name="VALUE" length="1948"/>
</property>
</class>

</hibernate-mapping>