[Hibernate-JIRA] Created: (HHH-2941) Criteria.createCriteria(associationPath) not works for Key-many-to-one
by Eddie Man (JIRA)
Criteria.createCriteria(associationPath) not works for Key-many-to-one
----------------------------------------------------------------------
Key: HHH-2941
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2941
Project: Hibernate3
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.2.4.sp1
Environment: Hibernate 3.2.4.sp1 + MySQL
Reporter: Eddie Man
Attachments: criteria_test.tar.gz
Suppose I had 2 class with the following content:
A.java
=================
public class A {
public A() {
}
public int ID;
public java.util.Set bs = new java.util.HashSet();
}
B.java
=================
import java.io.Serializable;
public class B implements Serializable {
public B() {
}
public int ID;
public A a;
}
A.hbm.xml
=================
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="A" table="A" lazy="false">
<id name="ID" column="ID" type="integer" unsaved-value="0" access="field">
<generator class="native">
</generator>
</id>
<set name="bs" lazy="true" cascade="save-update,lock" inverse="true" access="field">
<key column="AID" not-null="true"/>
<one-to-many class="B"/>
</set>
</class>
</hibernate-mapping>
B.hbm.xml
=================
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="B" table="B" lazy="false">
<composite-id>
<key-property name="ID" column="ID" type="integer" access="field"/>
<key-many-to-one name="a" column="AID" class="A" access="field">
</key-many-to-one>
</composite-id>
</class>
</hibernate-mapping>
Now, I want to find the B object with the specify B.ID and A.ID. Here is my code
Criteria criteria = session.createCriteria(B.class);
criteria.add(Expression.eq("ID", new Integer(2))); // B.ID = 2
criteria.createCriteria("a").add(Expression.eq("ID", new Integer(4))); // A.ID = 4
B b = (B) criteria.uniqueResult();
I turned on the show_sql in my configure file so that it will prompt all the sql statement in runtime, then executing the code, here is the printout:
09:35:59,096 WARN RootClass:211 - composite-id class does not override equals(): B
09:35:59,099 WARN RootClass:216 - composite-id class does not override hashCode(): B
Hibernate:
select
this_.ID as ID1_0_,
this_.AID as AID1_0_
from
B this_
where
this_.ID=?
and a1_.ID=?
09:35:59,982 WARN JDBCExceptionReporter:77 - SQL Error: 1054, SQLState: 42S22
09:35:59,982 ERROR JDBCExceptionReporter:78 - Unknown column 'a1_.ID' in 'where clause'
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1571)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:305)
at ListTestData.main(ListTestData.java:17)
Caused by: java.sql.SQLException: Unknown column 'a1_.ID' in 'where clause'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2978)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:930)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1024)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
... 7 more
It look like that the hibernate is missing the join table for the key-many-to-one. I had tested to using <key-property> and <many-to-one insert="false" update="false"> instread of <key-many-to-one>, and get no problem for that, so is it the bug on key many to one?
The schema and test case is attached.
Steps of reproduce the problem with the attached project:
=========
1. Execute the schema.ddl in to mysql db.
2. Execute java application "InsertTestData"
3. Record the last inserted id from the database and modify the "ListTestData" so that the expression value is correct.
4. Execute java application "ListTestData"
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
18 years, 4 months
[Hibernate-JIRA] Created: (EJB-286) Hibernate does not honor @Column(name=...) annotation with IdClass
by Dusty (JIRA)
Hibernate does not honor @Column(name=...) annotation with IdClass
------------------------------------------------------------------
Key: EJB-286
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-286
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.3.1.GA
Environment: Netbeans 5.5, Java6
Reporter: Dusty
I'have an Entity which uses an IdClass, when I execute the simplest query Hibernate fails because it's using the name of the attribute instead of the one indicated by the @Column annotation.
The IdClass is defined as follows:
public class DomainAdminId implements Serializable {
private String domainName;
private String adminUser;
public DomainAdminId() {
}
public DomainAdminId(String domainName, String adminUser) {
this.domainName = domainName;
this.adminUser = adminUser;
}
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public String getAdminUser() {
return adminUser;
}
public void setAdminUser(String adminUser) {
this.adminUser = adminUser;
}
public boolean equals(Object o) {
return ((o instanceof DomainAdminId) &&
domainName.equals(((DomainAdminId)o).getDomainName()) &&
adminUser.equals(((DomainAdminId)o).getAdminUser()));
}
public int hashCode() {
return (domainName+adminUser).hashCode();
}
}
And the following Entity using that idClass:
@Entity
@Table(name="domainadmin")
@IdClass(DomainAdminId.class)
@NamedQueries( {
@NamedQuery(name = "DomainAdmin.test", query = "SELECT d FROM DomainAdmin d")
)
public class DomainAdmin implements Serializable {
@Id
@Column(name="domain_name")
private String domainName;
@Id
@Column(name="adminuser")
private String adminUser;
public DomainAdmin() {
}
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public String getAdminUser() {
return adminUser;
}
public void setAdminUser(String adminUser) {
this.adminUser = adminUser;
}
}
When executing the DomainAdmin.test Named Query I got this error:
could not execute query [select domainadmi0_.adminUser as adminUser1_, domainadmi0_.domainName as domainName1_ from domainadmin domainadmi0_]
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'domainadmi0_.domainName' in 'field list'
In effect, as indicated in the source, the column name is "domain_name" and not "domainName".
The same apply for the other column: adminUser (that should instead be "adminuser"),
This issue is blocking for me, do you have any workaround for the time being?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
18 years, 4 months
[Hibernate-JIRA] Created: (HHH-2978) Using HQL index() on a <index-many-to-many..> key in a <map...> cannot dereference any properties of the key - java.lang.NullPointerException
by James Andrews (JIRA)
Using HQL index() on a <index-many-to-many..> key in a <map...> cannot dereference any properties of the key - java.lang.NullPointerException
---------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-2978
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2978
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.2.5
Environment: Hibernate 3.2.5 GA, MySQL 5.0.27 Community NT, Eclipse 3.1.1, Hibernate Tools 3.2 beta 9
Reporter: James Andrews
As mentioned in summary, using a mapped POJO as the index of a <map..> relationship, via the <index-many-to-many class="..> approach.
Using a table join, for instance:
select index(depts), depts
from ModificationFixed fixed
left join fixed.departments depts
Will fetch Department instances for each value, but if you instead try to fetch a property of the index:
select index(depts).name, depts
from ModificationFixed fixed
left join fixed.departments depts
then this causes the aforementioned NullPointerException, both in the hibernate tools preview, and in practise when trying to execute the query, with the following stack trace:
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:444)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1080)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1881)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1825)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1394)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:553)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:115)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at intranet.db.PersistentMySQL.createQueryArray(PersistentMySQL.java:154)
at intranet.budget.planner.ModificationFixed.main(ModificationFixed.java:165)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
18 years, 4 months
[Hibernate-JIRA] Created: (HHH-2709) Informix dialect generates incorrect ALTER TABLE statement
by Ovidiu Feodorov (JIRA)
Informix dialect generates incorrect ALTER TABLE statement
----------------------------------------------------------
Key: HHH-2709
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2709
Project: Hibernate3
Issue Type: Bug
Components: metamodel
Affects Versions: 3.2.4, 3.2.3, 3.2.2, 3.2.1
Environment: Informix Dynamic Server 10.00.UC6, JDBC driver 3.00.JC3
Reporter: Ovidiu Feodorov
org.hibernate.dialect.InformixDialect shipping with Hibernate 3.2.1 - 3.2.4 generates corrupted SQL, at least relative to Informix Dynamic Server 10.00.UC6.
2007-07-02 18:14:47,011 ERROR SchemaExport:274 - Unsuccessful: alter table A add constraint foreign key (B_ID) references collection constraint FK4AA13DBAA4271173 on delete cascade
2007-07-02 18:14:47,011 ERROR SchemaExport:275 - A syntax error has occurred.
This is what the Dialect generates:
alter table A add constraint foreign key ( B_ID) references collection constraint FKBC16C978A4271173 on delete cascade
This is what works:
alter table A add constraint foreign key (B_ID) references collection on delete cascade constraint FKBC16C978A4271173
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
18 years, 4 months