[Hibernate-JIRA] Created: (HBX-1177) hbm2hbmxml task generates error for @ElementCollection annotation
by Grzegorz Aniol (JIRA)
hbm2hbmxml task generates error for @ElementCollection annotation
-----------------------------------------------------------------
Key: HBX-1177
URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-1177
Project: Hibernate Tools
Issue Type: Bug
Components: ant
Reporter: Grzegorz Aniol
Affected version is 3.4.0CR1.
I'm running hbm2hbmxml task from ant script to generate hibernate mapping files based on annotations in entities.
I'm getting an error: "Expression property.cascade is undefined on line 10, column 14 in hbm/map.hbm.ftl" for an entity which is using @ElementCollection annotation.
====================================================================
Here is the example of a class:
====================================================================
@Entity
@Table(name = "configentry2")
public class ClassA {
@Id
@Column(name = "id")
private int id;
@ElementCollection
@MapKeyColumn(name = "key")
@Column(name = "value", columnDefinition="TEXT")
@CollectionTable(name = "configentry_map2", joinColumns = @JoinColumn(name = "configentry_id"))
@ForeignKey(name = "fk_belongs_to_config")
private Map<String, String> entries;
}
====================================================================
Here is the full exception stack:
====================================================================
<CUT>\build.xml:83: org.hibernate.tool.hbm2x.ExporterException: Error while
processing Entity: <CUT>.ClassA with template hbm/hibernate-mapping.hbm.ftl
at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:261)
at org.hibernate.tool.hbm2x.TemplateProducer.produceToString(TemplateProducer.java:67)
at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.java:28)
at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.java:103)
at org.hibernate.tool.hbm2x.GenericExporter.exportPOJO(GenericExporter.java:148)
at org.hibernate.tool.hbm2x.GenericExporter.exportPersistentClass(GenericExporter.java:137)
at org.hibernate.tool.hbm2x.GenericExporter$2.process(GenericExporter.java:43)
at org.hibernate.tool.hbm2x.GenericExporter.doStart(GenericExporter.java:128)
at org.hibernate.tool.hbm2x.HibernateMappingExporter.doStart(HibernateMappingExporter.java:34)
at org.hibernate.tool.hbm2x.AbstractExporter.start(AbstractExporter.java:95)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:40)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1397)
at org.apache.tools.ant.Project.executeTarget(Project.java:1366)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1249)
at org.apache.tools.ant.Main.runBuild(Main.java:801)
at org.apache.tools.ant.Main.startAnt(Main.java:218)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: freemarker.core.InvalidReferenceException: Expression property.cascade is undefined on line 10, column 14 in hbm/map.hb
m.ftl.
at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
at freemarker.core.ComparisonExpression.isTrue(ComparisonExpression.java:121)
at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:77)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.Environment.include(Environment.java:1375)
at freemarker.core.Include.accept(Include.java:155)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:160)
at freemarker.core.Environment.visit(Environment.java:351)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:95)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.Environment.include(Environment.java:1375)
at freemarker.core.Include.accept(Include.java:155)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.Environment.process(Environment.java:176)
at freemarker.template.Template.process(Template.java:232)
at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:255)
... 27 more
--
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
13 years, 6 months
[Hibernate-JIRA] Created: (HHH-5946) Wrong generated SQL when used composite user type in HQL with not equal operator
by Emanuele Gesuato (JIRA)
Wrong generated SQL when used composite user type in HQL with not equal operator
--------------------------------------------------------------------------------
Key: HHH-5946
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5946
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.1
Environment: hibernate version 3.6.1, databases db2 and oracle
Reporter: Emanuele Gesuato
Attachments: CompositeUserTypeTest.java, patch.txt
If i use a not operator in a hql query using a composite user type (that uses at least two fields) the sql generated has an AND statement between the elements but i expect an OR instead.
I have tried to reproduce a bug using an hibernate test case.
In particular using the following class:
{code:title=org.hibernate.test.cut.Transaction.java|borderStyle=solid}
public class Transaction {
private Long id;
private String description;
private MonetoryAmount value;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public MonetoryAmount getValue() {
return value;
}
public void setValue(MonetoryAmount value) {
this.value = value;
}
}
{code}
i've modified CompositeUserTypeTest.testCompositeUserType (present in hibernate tests) as following (added the last two lines inside if statement):
{code:title=org.hibernate.test.cut.CompositeUserTypeTest.java|borderStyle=solid}
public void testCompositeUserType() {
Session s = openSession();
org.hibernate.Transaction t = s.beginTransaction();
Transaction tran = new Transaction();
tran.setDescription("a small transaction");
tran.setValue( new MonetoryAmount( new BigDecimal(1.5), Currency.getInstance("USD") ) );
s.persist(tran);
List result = s.createQuery("from Transaction tran where tran.value.amount > 1.0 and tran.value.currency = 'USD'").list();
assertEquals( result.size(), 1 );
tran.getValue().setCurrency( Currency.getInstance("AUD") );
result = s.createQuery("from Transaction tran where tran.value.amount > 1.0 and tran.value.currency = 'AUD'").list();
assertEquals( result.size(), 1 );
if ( !(getDialect() instanceof HSQLDialect) ) {
result = s.createQuery("from Transaction txn where txn.value = (1.5, 'AUD')").list();
assertEquals( result.size(), 1 );
result = s.createQuery("from Transaction where value = (1.5, 'AUD')").list();
assertEquals( result.size(), 1 );
result = s.createQuery("from Transaction where value != (1.4, 'AUD')").list();
assertEquals( result.size(), 1 );
}
s.delete(tran);
t.commit();
s.close();
}
{code}
the last assert should succeed because transaction (1.5, 'AUD') isn't equal to (1.4, 'AUD') and i should retrieve the (1.5, 'AUD') but the sql generated has an "AND" instead of an "OR":
{code:title=Generated SQL|borderStyle=solid}
select
transactio0_.id as id0_,
transactio0_.description as descript2_0_,
transactio0_.amount as amount0_,
transactio0_.currency as currency0_
from
Trnsctn transactio0_
where
transactio0_.amount<>1.4
and transactio0_.currency<>'AUD'
{code}
In attachment i provide a patch and the full modified test case.
--
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
13 years, 6 months
[Hibernate-JIRA] Created: (HHH-5886) Inequality operator (<>) on component/composite-id uses AND instead of OR between atomic fields comparison
by Paizo (JIRA)
Inequality operator (<>) on component/composite-id uses AND instead of OR between atomic fields comparison
----------------------------------------------------------------------------------------------------------
Key: HHH-5886
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5886
Project: Hibernate Core
Issue Type: Bug
Components: query-sql
Affects Versions: 3.2.7
Environment: 3.2.7GA, jetty, H2/oracle 11g/DB2 v9
Reporter: Paizo
As described here: [https://forum.hibernate.org/viewtopic.php?f=1&t=1009229&start=0]
given this mapping snippet:
{quote}
<class name="d.p.entityIDMUnit.lim.bl.pom.impl.PPKone" table="PPKone">
<composite-id>
<key-property name="i" type="IntegerType">
<column name="c_i_5b145" precision="19" scale="0"/>
</key-property>
<key-property name="j" type="IntegerType">
<column name="c_j_4534d" precision="19" scale="0"/>
</key-property>
</composite-id>
...
{quote}
and the following HQL:
from d.p.entityIDMUnit.lim.bl.pom.impl.PPKone p where (( ( p <> p ) and ( p.i = 1 ) ))
The SQL where statement looks:
where
*ppkone0_.c_i_5b145<>ppkone0_.c_i_5b145
{color:red} and {color} ppkone0_.c_j_4534d<>ppkone0_.c_j_4534d*
and ppkone0_.c_i_5b145=1
when it should be:
*{color:red}({color}ppkone0_.c_i_5b145<>ppkone0_.c_i_5b145
{color:red} OR {color} ppkone0_.c_j_4534d<>ppkone0_.c_j_4534d{color:red}){color}*
or ppkone0_.c_i_5b145=1
A component/composite-id is different from another one if at least ONE of its fields is different, not only when all the fields are different
--
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
13 years, 6 months
[Hibernate-JIRA] Created: (HHH-5972) ClassCastException using SimpleExpression.ignoreCase on not VARCHAR property type
by Pawel Omelko (JIRA)
ClassCastException using SimpleExpression.ignoreCase on not VARCHAR property type
---------------------------------------------------------------------------------
Key: HHH-5972
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5972
Project: Hibernate Core
Issue Type: New Feature
Components: query-criteria
Affects Versions: 3.6.1, 3.3.2
Environment: 3.3.2, postgresql 8.3
Reporter: Pawel Omelko
For given criteria:
hibernateTemplate.executeFind(new HibernateCallback() {
@Override
public Object doInHibernate(Session session) throws HibernateException, SQLException {
return session.createCriteria(Cat.class).add(Restrictions.eq("age", 7).ignoreCase()).list();
}
});
where "age" is Integer field of Cat.class, i have an exception:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at org.hibernate.type.IntegerType.set(IntegerType.java:64)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1732)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1703)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1593)
at org.hibernate.loader.Loader.doQuery(Loader.java:696)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2232)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2124)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1597)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
I found somtthink like this in SimpleExpression.toSqlString(...) method
boolean lower = ignoreCase && ( sqlTypes[i]==Types.VARCHAR || sqlTypes[i]==Types.CHAR );
if (lower) {
//do something
}
I think that, same conditon should be added in method getTypedValues(...)
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
//some needed code
boolean lower = ignoreCase && ( sqlTypes[i]==Types.VARCHAR || sqlTypes[i]==Types.CHAR );
Object icvalue = lower ? value.toString().toLowerCase() : value;
return new TypedValue[] { criteriaQuery.getTypedValue(criteria, propertyName, icvalue) };
}
but now, only ignoreCase condition is checked:
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
Object icvalue = ignoreCase ? value.toString().toLowerCase() : value;
return new TypedValue[] { criteriaQuery.getTypedValue(criteria, propertyName, icvalue) };
}
Is any technical reason why sqlType in getTypedValues(...) method is not checked?
--
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
13 years, 6 months
[Hibernate-JIRA] Created: (HHH-5970) Error in filter-def condition attribute definition caused by trim sql function
by Tomáš Šafařík (JIRA)
Error in filter-def condition attribute definition caused by trim sql function
------------------------------------------------------------------------------
Key: HHH-5970
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5970
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.0
Reporter: Tomáš Šafařík
I have encountered an error that in filter-def definition in condition attribute is not possible to use SQL function trim with expression.
For example this definition: <filter-def name="concatInTrim" condition="TRIM(CONCAT(TITLE,TITLE)) IS NOT NULL" /> causes this error:
-------------------------------------------------------------------------------
Test set: org.hibernate.test.function.trim.FunctionTrimTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.698 sec <<< FAILURE!
testBasicUsage(org.hibernate.test.function.trim.FunctionTrimTest) Time elapsed: 0.659 sec <<< ERROR!
org.hibernate.HibernateException: Unexpected number of trim function operands : 5
at org.hibernate.sql.Template$TrimOperands.<init>(Template.java:582)
at org.hibernate.sql.Template$TrimOperands.<init>(Template.java:561)
at org.hibernate.sql.Template.renderWhereStringTemplate(Template.java:248)
at org.hibernate.util.FilterHelper.<init>(FilterHelper.java:63)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:737)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:133)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:284)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842)
at org.hibernate.test.function.trim.FunctionTrimTest.setUp(FunctionTrimTest.java:24)
at junit.framework.TestCase.runBare(TestCase.java:132)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:115)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:102)
at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
I think, that this problem is caused by function org.hibernate.sql.Template.renderWhereStringTemplate(), that doesn't take into account possibility of expression in trim function argument.
I think that this problem is related to http://opensource.atlassian.com/projects/hibernate/browse/HHH-5676?page=c....
In attachment is test case based on Hibernate tutorial (hbm.xml Tutorial).
--
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
13 years, 6 months