[Hibernate-JIRA] Commented: (HHH-1452) Native SQL query is missing join if entity includes many-to-one on secondary table
by Razan Abbass (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1452?page=c... ]
Razan Abbass commented on HHH-1452:
-----------------------------------
[cheap airline tickets|http://getflightsto.com]
[Parenting|http://childcareforums.com]
> Native SQL query is missing join if entity includes many-to-one on secondary table
> ----------------------------------------------------------------------------------
>
> Key: HHH-1452
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1452
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.1.2
> Reporter: Christian Bauer
> Priority: Minor
> Fix For: 3.2.0.cr3
>
>
> Mapping of a many-to-one across a join table:
> <class name="Item">
> <join table="ITEM_BUYER"
> optional="true">
> <key column="ITEM_ID"/>
> <many-to-one name="buyer" column="USER_ID"/>
> </join>
> </class>
> Query:
> result = session.createSQLQuery("select {i.*} from ITEM i" +
> " join USERS u on i.SELLER_ID = u.USER_ID" +
> " where u.USERNAME = :uname")
> .addEntity("i", Item.class)
> .setParameter("uname", "turin")
> .list();
> Generated SQL and exception:
> Hibernate:
> /* dynamic native SQL query */ select
> i.ITEM_ID as ITEM1_7_0_,
> i.OBJ_VERSION as OBJ2_7_0_,
> i.NAME as NAME7_0_,
> i.DESCRIPTION as DESCRIPT4_7_0_,
> i.INITIAL_PRICE as INITIAL5_7_0_,
> i.INITIAL_PRICE_CURRENCY as INITIAL6_7_0_,
> i.RESERVE_PRICE as RESERVE7_7_0_,
> i.RESERVE_PRICE_CURRENCY as RESERVE8_7_0_,
> i.START_DATE as START9_7_0_,
> i.END_DATE as END10_7_0_,
> i.STATE as STATE7_0_,
> i.APPROVAL_DATETIME as APPROVAL12_7_0_,
> i.CREATED as CREATED7_0_,
> i.APPROVED_BY_USER_ID as APPROVED14_7_0_,
> i.SELLER_ID as SELLER15_7_0_,
> i_1_.USER_ID as USER2_2_0_,
> 'T' as formula0_0_,
> i.ITEM_ID as formula1_0_
> from
> ITEM i
> join
> USERS u
> on i.SELLER_ID = u.USER_ID
> where
> u.USERNAME = ?
> 03:45:18,243 WARN JDBCExceptionReporter:71 - SQL Error: -28, SQLState: S0022
> 03:45:18,244 ERROR JDBCExceptionReporter:72 - Column not found: I_1_.USER_ID in statement [/* dynamic native SQL query */ select i.ITEM_ID as ITEM1_7_0_, i.OBJ_VERSION as OBJ2_7_0_, i.NAME as NAME7_0_, i.DESCRIPTION as DESCRIPT4_7_0_, i.INITIAL_PRICE as INITIAL5_7_0_, i.INITIAL_PRICE_CURRENCY as INITIAL6_7_0_, i.RESERVE_PRICE as RESERVE7_7_0_, i.RESERVE_PRICE_CURRENCY as RESERVE8_7_0_, i.START_DATE as START9_7_0_, i.END_DATE as END10_7_0_, i.STATE as STATE7_0_, i.APPROVAL_DATETIME as APPROVAL12_7_0_, i.CREATED as CREATED7_0_, i.APPROVED_BY_USER_ID as APPROVED14_7_0_, i.SELLER_ID as SELLER15_7_0_, i_1_.USER_ID as USER2_2_0_, 'T' as formula0_0_, i.ITEM_ID as formula1_0_ from ITEM i join USERS u on i.SELLER_ID = u.USER_ID where u.USERNAME = ?]
--
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, 8 months
[Hibernate-JIRA] Commented: (HBX-265) dynamicUpdate property in Entity annotation not work
by Razan Abbass (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HBX-265?page=co... ]
Razan Abbass commented on HBX-265:
----------------------------------
[cheap airline tickets|http://getflightsto.com]
[Parenting|http://childcareforums.com]
> dynamicUpdate property in Entity annotation not work
> ----------------------------------------------------
>
> Key: HBX-265
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-265
> Project: Hibernate Tools
> Issue Type: Bug
> Components: annotations (obsolete)
> Affects Versions: 3.0beta1
> Environment: Hibernate 3 hibernate annotations 3.0 beta1
> Reporter: Rogerio Saulo
> Fix For: 3.0beta2
>
>
> The property dynamicUpdate when set on the Entity annotation does not remove NULL columns from the UPDATE statement.
> For the dynamicInsert it is working.
> Below is my POJO, code to execute and generated UPDATE Statement.
> POJO :
> ------------------------------------------------------------------
> @Entity
> @org.hibernate.annotations.Entity ( dynamicInsert = true, dynamicUpdate = true )
> @Table (name = "USERS")
> @javax.persistence.GeneratedIdTable(
> name="GEN_TABLE",
> table = @Table(name="VENUS_IDS"),
> pkColumnName = "KEY_ID",
> valueColumnName = "LAST_VALUE"
> )
> @javax.persistence.TableGenerator(
> name="USERS_GEN",
> tableName="GEN_TABLE",
> pkColumnValue="ID_USER",
> allocationSize=1
> )
> public class UserVO implements Serializable {
>
> private Integer id_user;
> private String login;
> private String email;
> private String passwd;
> private Timestamp creation_timestamp;
> private Timestamp last_change_timestamp;
>
> @Column (name = "creation_timestamp")
> public Timestamp getCreation_timestamp() {
> return creation_timestamp;
> }
> @Column (name = "email")
> public String getEmail() {
> return email;
> }
> @Id (generate=GeneratorType.TABLE, generator="USERS_GEN")
> public Integer getId_user() {
> return id_user;
> }
> @Column (name = "last_change_timestamp")
> public Timestamp getLast_change_timestamp() {
> return last_change_timestamp;
> }
> @Column (name = "login")
> public String getLogin() {
> return login;
> }
> @Column (name = "passwd")
> public String getPasswd() {
> return passwd;
> }
> .... (Setters come here)
> }
> --------------------------------------------------------------------
> Code executing :
> --------------------------------------------------------------------
> UserVO obj = new UserVO();
> obj.setId_user(new Integer(1));
> obj.setEmail("alterado(a)teste.com");
>
> session.update(obj);
> --------------------------------------------------------------------
> Generated update statement :
> Hibernate: update USERS set creation_timestamp=?, last_change_timestamp=?, email=?, login=?, passwd=? where id_user=?
> --------------------------------------------------------------------
> Thanks in advance.
--
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, 8 months
[Hibernate-JIRA] Commented: (HHH-1452) Native SQL query is missing join if entity includes many-to-one on secondary table
by Razan Abbass (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1452?page=c... ]
Razan Abbass commented on HHH-1452:
-----------------------------------
[cheap airline tickets|http://getflightsto.com]
[Parenting|http://childcareforums.com]
> Native SQL query is missing join if entity includes many-to-one on secondary table
> ----------------------------------------------------------------------------------
>
> Key: HHH-1452
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1452
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.1.2
> Reporter: Christian Bauer
> Priority: Minor
> Fix For: 3.2.0.cr3
>
>
> Mapping of a many-to-one across a join table:
> <class name="Item">
> <join table="ITEM_BUYER"
> optional="true">
> <key column="ITEM_ID"/>
> <many-to-one name="buyer" column="USER_ID"/>
> </join>
> </class>
> Query:
> result = session.createSQLQuery("select {i.*} from ITEM i" +
> " join USERS u on i.SELLER_ID = u.USER_ID" +
> " where u.USERNAME = :uname")
> .addEntity("i", Item.class)
> .setParameter("uname", "turin")
> .list();
> Generated SQL and exception:
> Hibernate:
> /* dynamic native SQL query */ select
> i.ITEM_ID as ITEM1_7_0_,
> i.OBJ_VERSION as OBJ2_7_0_,
> i.NAME as NAME7_0_,
> i.DESCRIPTION as DESCRIPT4_7_0_,
> i.INITIAL_PRICE as INITIAL5_7_0_,
> i.INITIAL_PRICE_CURRENCY as INITIAL6_7_0_,
> i.RESERVE_PRICE as RESERVE7_7_0_,
> i.RESERVE_PRICE_CURRENCY as RESERVE8_7_0_,
> i.START_DATE as START9_7_0_,
> i.END_DATE as END10_7_0_,
> i.STATE as STATE7_0_,
> i.APPROVAL_DATETIME as APPROVAL12_7_0_,
> i.CREATED as CREATED7_0_,
> i.APPROVED_BY_USER_ID as APPROVED14_7_0_,
> i.SELLER_ID as SELLER15_7_0_,
> i_1_.USER_ID as USER2_2_0_,
> 'T' as formula0_0_,
> i.ITEM_ID as formula1_0_
> from
> ITEM i
> join
> USERS u
> on i.SELLER_ID = u.USER_ID
> where
> u.USERNAME = ?
> 03:45:18,243 WARN JDBCExceptionReporter:71 - SQL Error: -28, SQLState: S0022
> 03:45:18,244 ERROR JDBCExceptionReporter:72 - Column not found: I_1_.USER_ID in statement [/* dynamic native SQL query */ select i.ITEM_ID as ITEM1_7_0_, i.OBJ_VERSION as OBJ2_7_0_, i.NAME as NAME7_0_, i.DESCRIPTION as DESCRIPT4_7_0_, i.INITIAL_PRICE as INITIAL5_7_0_, i.INITIAL_PRICE_CURRENCY as INITIAL6_7_0_, i.RESERVE_PRICE as RESERVE7_7_0_, i.RESERVE_PRICE_CURRENCY as RESERVE8_7_0_, i.START_DATE as START9_7_0_, i.END_DATE as END10_7_0_, i.STATE as STATE7_0_, i.APPROVAL_DATETIME as APPROVAL12_7_0_, i.CREATED as CREATED7_0_, i.APPROVED_BY_USER_ID as APPROVED14_7_0_, i.SELLER_ID as SELLER15_7_0_, i_1_.USER_ID as USER2_2_0_, 'T' as formula0_0_, i.ITEM_ID as formula1_0_ from ITEM i join USERS u on i.SELLER_ID = u.USER_ID where u.USERNAME = ?]
--
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, 8 months
[Hibernate-JIRA] Commented: (HHH-993) Criteria subquery without projection fails throwing NullPointerException
by Razan Abbass (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-993?page=co... ]
Razan Abbass commented on HHH-993:
----------------------------------
[cheap airline tickets|http://getflightsto.com]
[Parenting|http://childcareforums.com]
> Criteria subquery without projection fails throwing NullPointerException
> ------------------------------------------------------------------------
>
> Key: HHH-993
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-993
> Project: Hibernate Core
> Issue Type: Improvement
> Components: core
> Reporter: Johannes Rudolph
> Priority: Minor
>
> If you use a subquery in a criteria query and there is no projection, the execution of the query will fail by throwing a NullPointerException:
> Caused by: java.lang.NullPointerException
> at
> org.hibernate.loader.criteria.CriteriaQueryTranslator.getProjectedTypes(Crit
> eriaQueryTranslator.java:298)
> at
> org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.ja
> va:56)
> at
> org.hibernate.criterion.LogicalExpression.toSqlString(LogicalExpression.java
> :39)
> org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(Crit
> eriaQueryTranslator.java:314)
> ...
> I think it is expected behaviour that restrictions only work on 1-dimensional return values of subqueries so it would be nice if Hibernate would mention that somewhere.
> It would be nice if you could just write:
> Criteria crit = dbSession.createCriteria(Bla.class);
> DetachedCriteria detachedCrit = DetachedCriteria.forClass(Blub.class).add( Restrictions.eq("condition", Boolean.FALSE));
> crit.add( Restrictions.or( Restrictions.isNull("superBlub"),
> Subqueries.in("superBlub", detachedCrit ) ) );
> since Hibernate entities could be seen as "entities" so Hibernate should automatically transform it into:
> DetachedCriteria detachedCrit = DetachedCriteria.forClass(Blub.class).add( Restrictions.eq("condition", Boolean.FALSE))
> .setProjection( Projections.id() );
> crit.add( Restrictions.or( Restrictions.isNull("superBlub"),
> Subqueries.propertyIn("ueberPartner", detachedCrit ) ) );
--
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, 8 months
[Hibernate-JIRA] Commented: (HHH-245) SelectGenerator Patch
by Razan Abbass (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-245?page=co... ]
Razan Abbass commented on HHH-245:
----------------------------------
[cheap airline tickets|http://getflightsto.com]
[Parenting|http://childcareforums.com]
> SelectGenerator Patch
> ---------------------
>
> Key: HHH-245
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-245
> Project: Hibernate Core
> Issue Type: Patch
> Environment: H3
> Oracle 9iJDK 1.5.0
> Reporter: Malcolm Green
> Assignee: Gavin King
> Fix For: 3.0 final
>
> Attachments: SelectGenerator.diff
>
>
> Trying to use the SelectGenerator as Primary ID of record is populated via a trigger and getting the following error.
> java.lang.String
> java.lang.ClassCastException: java.lang.String
> at org.hibernate.type.LongType.set(LongType.java:40)
> at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
> at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
> at org.hibernate.id.SelectGenerator.bindParameters(SelectGenerator.java:51)
> at org.hibernate.id.AbstractPostInsertGenerator.getGenerated(AbstractPostInsertGenerator.java:41)
> at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1755)
> at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2149)
> at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:34)
> at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
> at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:238)
> at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:158)
> at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
> at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
> at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:429)
> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:424)
> ..........
> I narrowed this down to the fact that the code assumes that the uniqueKeyPropertyType is the same type as the ID. I personally think that this is slightly restrictive and so have amended the code accordingly.
> .............
> The next thrown exception is as follows:
> java.sql.SQLException: ResultSet.next was not called
> at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
> at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
> at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
> at oracle.jdbc.driver.OracleStatement.prepare_for_new_get(OracleStatement.java:3202)
> at oracle.jdbc.driver.OracleStatement.getLongValue(OracleStatement.java:4341)
> at oracle.jdbc.driver.OracleResultSetImpl.getLong(OracleResultSetImpl.java:529)
> at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:1540)
> at org.hibernate.type.LongType.get(LongType.java:26)
> at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
> at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
> at org.hibernate.id.SelectGenerator.getResult(SelectGenerator.java:57)
> at org.hibernate.id.AbstractPostInsertGenerator.getGenerated(AbstractPostInsertGenerator.java:44)
> at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1755)
> at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2149)
> at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:34)
> at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
> at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:238)
> at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:158)
> at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
> at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
> at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
> at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:429)
> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:424)
> at hsbc.greaterniku.model.RITFTest.testCreateRITF(RITFTest.java:56)
> 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:585)
> at junit.framework.TestCase.runTest(TestCase.java:154)
> at junit.framework.TestCase.runBare(TestCase.java:127)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:118)
> at junit.framework.TestSuite.runTest(TestSuite.java:208)
> at junit.framework.TestSuite.run(TestSuite.java:203)
> at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:289)
> at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:656)
> at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:558)
> ..................
> Obviously this is because ResultSet.next isn't being called ;-)
> I have amended the code again but am not totally convinced that I have put the rs.next() call in the correct place.
> Please accept my apologies if I have not posted this in the correct way, but this is the first time I have contributed to an Opensource project.
--
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, 8 months
[Hibernate-JIRA] Commented: (HHH-1523) Rebuild fetches from query-cache hits
by Titi Wangsa bin Damhore (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1523?page=c... ]
Titi Wangsa bin Damhore commented on HHH-1523:
----------------------------------------------
I've just been hit by the problem and it took me a while to debug it.
I'm using hibernate-core-3.5.6-Final
The code is in org.hibernate.event.def.DefaultLoadEventListener line 254, method "proxyOrLoad"
This is the function that will load the actual object from session or from the db, but it does not check for the existence of the object in second level cache.
Line 360, method createProxyIfNecessary is where the proxy actually get created.
What I've done is copy the whole source code to my class, "CustomLoadEventListener" (I'd prefer inheritance, but the method I want to modify is a private method), and change line 358 - 363
log.trace( "creating new proxy for entity" );
// return new uninitialized proxy
Object proxy = persister.createProxy( event.getEntityId(), event.getSession() );
persistenceContext.getBatchFetchQueue().addBatchLoadableEntityKey(keyToLoad);
persistenceContext.addProxy(keyToLoad, proxy);
return proxy;
to
final Object cached = loadFromSecondLevelCache(event, persister, options);
if (cached != null) {
return cached;
} else {
log.trace("creating new proxy for entity");
// return new uninitialized proxy
final Object proxy = persister.createProxy(event.getEntityId(), event.getSession());
persistenceContext.getBatchFetchQueue().addBatchLoadableEntityKey(keyToLoad);
persistenceContext.addProxy(keyToLoad, proxy);
return proxy;
}
and reconfigure hibernate to use the new LoadEventListener
i am not sure about the performance implication of this, but it gets rid of my "LazyInitializationException"
> Rebuild fetches from query-cache hits
> -------------------------------------
>
> Key: HHH-1523
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1523
> Project: Hibernate Core
> Issue Type: New Feature
> Components: caching (L2), core, query-criteria, query-hql, query-sql
> Affects Versions: 3.0.5, 3.1
> Reporter: Vikas Sasidharan
> Attachments: cache_issue.log, QueryCacheIssue.zip
>
>
> I have two domain objects - Employee and Department - and there is a 1:N relationship from Department to Employee. When I join fetch an Employee with its Department, without query cache enabled, it works fine. If I enable query cache for this same query, it bombs with a LazyInitializationException.
> Notes:
> 1) We get this error only if query cache is enabled.
> 2) We observed the same behaviour on both oscache and ehcache
> 3) Calling Hibernate.initialize() explicitly after firing the HQL seems to work. The initialization does not fire an extra query though (it seems to pick it from the cache).
> 4) Setting "lazy=false" on the "many-to-one" mapping also works. However, it wouldn't be acceptable.
> Hibernate version: 3.0.5
> Mapping documents:
> Employee.hbm.xml
> <hibernate-mapping>
> <class name="tavant.platform.test.domain.Employee"
> table="CACHE_ISSUE_EMP" lazy="true" dynamic-update="true" dynamic-insert="true">
> <cache usage="read-write" />
> <id name="id" column="EMP_ID" type="java.lang.Long"
> access="field" unsaved-value="null">
> <generator class="increment" />
> </id>
>
> <property name="name" type="string" update="true"
> insert="true" column="EMP_NAME"/>
> <many-to-one name="department" class="tavant.platform.test.domain.Department"
> cascade="none" outer-join="auto" update="true" insert="true" column="DEPARTMENT_ID"/>
> </class>
> </hibernate-mapping>
>
> Department.hbm.xml
> <hibernate-mapping>
> <class name="tavant.platform.test.domain.Department" table="CACHE_ISSUE_DEP"
> lazy="true" dynamic-update="true" dynamic-insert="true">
>
> <cache usage="read-write" />
> <id name="id" column="DEPARTMENT_ID"
> type="java.lang.Long" access="field">
> <generator class="increment"/>
> </id>
> <property name="name" type="java.lang.String"
> update="false" insert="true" column="NAME"/>
> <bag name="employees" lazy="true"
> inverse="true" cascade="save-update" access="field">
> <cache usage="read-write"/>
> <key column="DEPARTMENT_ID"/>
> <one-to-many class="tavant.platform.test.domain.Employee"/>
> </bag>
> </class>
> </hibernate-mapping>
>
> Code between sessionFactory.openSession() and session.close():
> public Employee getEmployeeWithDepartment(String empName) {
> Session session = null;
> try {
> session = sessionFactory.openSession();
> Employee emp = (Employee) session.createQuery(
> "from Employee e join fetch e.department where e.name = :name")
> .setString("name", empName)
> .setCacheable(true)
> .uniqueResult();
> // If I uncomment the next line, this works (even without
> // firing an extra query)!
> // Hibernate.initialize(emp.getDepartment());
> return emp;
> } finally {
> if (session != null) {
> session.close();
> }
> }
> }
>
> // First load employee and populate cahces
> Employee emp = test.getEmployeeWithDepartment(EMPLOYEE_NAME);
> System.out.println("Employee : " + emp + ", Employee.Department : "
> + emp.getDepartment());
>
> // Now try to make use of the cache
> emp = test.getEmployeeWithDepartment(EMPLOYEE_NAME);
> System.out.println("Employee : " + emp + ", Employee.Department : "
> + emp.getDepartment());
>
> Full stack trace of any exception that occurs:
> org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
> at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
> at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
> at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
> at tavant.platform.test.domain.Department$$EnhancerByCGLIB$$67b26899.toString(<generated>)
> at java.lang.String.valueOf(String.java:2131)
> at java.lang.StringBuffer.append(StringBuffer.java:370)
> at tavant.platform.test.client.TestPrefetchRelationWithQueryCacheEnabled.main(TestPrefetchRelationWithQueryCacheEnabled.java:116)
>
> Name and version of the database you are using:
> We have noticed this on Oracle and HSQL
> The generated SQL (show_sql=true):
> #First read, goes fine
> Hibernate: select employee0_.EMP_ID as EMP1_0_, department1_.DEPARTMENT_ID as DEPARTMENT1_1_, employee0_.EMP_NAME as EMP2_1_0_, employee0_.DEPARTMENT_ID as DEPARTMENT3_1_0_, department1_.NAME as NAME0_1_ from CACHE_ISSUE_EMP employee0_ inner join CACHE_ISSUE_DEP department1_ on employee0_.DEPARTMENT_ID=department1_.DEPARTMENT_ID where (employee0_.EMP_NAME=? )
> #Prints the Employee and Department fine
> Employee : [Id : 1, name : testEmployee], Employee.Department : [Id : 1, name : testDepartment]
> #Second read bombs!
> org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
> at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
> at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
> at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
> [..]
> Please have a look at the post [http://forum.hibernate.org/viewtopic.php?t=955839] for more details and follow ups.
> Kindly help. I am attaching an Eclipse Project containing the TestCase. The main file is TestPrefetchRelationWithQueryCacheEnabled.
> Thanks,
> Vikas
--
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, 8 months
[Hibernate-JIRA] Created: (HHH-3834) Exception: cast() requires two arguments
by Paulo Angelo (JIRA)
Exception: cast() requires two arguments
----------------------------------------
Key: HHH-3834
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3834
Project: Hibernate Core
Issue Type: Bug
Environment: hibernate3, postgresql 8.3
Reporter: Paulo Angelo
Got exaclty the same as in HHH-3285 .:
cast() requires two arguments [select f from MenuItem f where ( ( UPPER( TO_ASCII(CAST(convert(f.Menu.Idme, 'UTF8', 'LATIN1') , TEXT),'LATIN1')) LIKE UPPER( TO_ASCII(CAST(convert('M10', 'UTF8', 'LATIN1') , TEXT),'LATIN1')) ) ) order by f.Orde ASC ]
But there is not a extra ")" (I think, :) )
--
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, 8 months