[Hibernate-JIRA] Commented: (HHH-1523) LazyInitializationError on enabling query cache...
by Faizal Abdoelrahman (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1523?page=c... ]
Faizal Abdoelrahman commented on HHH-1523:
------------------------------------------
I ran into the same issue when enabling the query cache with lazy many-to-one associations.
The problem went away when changing:
<cache usage="read-write" />
into
<cache usage="read-write" include="all"/>
To cache the lazy ends.
Hopes this solves your issue as well.
Regards,
Faizal Abdoelrahman
> LazyInitializationError on enabling query cache...
> --------------------------------------------------
>
> Key: HHH-1523
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1523
> Project: Hibernate3
> Issue Type: Bug
> Components: core
> Affects Versions: 3.0.5, 3.1
> Environment: 3.0.1 and 3.1, HSQLDB and Oracle
> 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
16 years, 5 months
[Hibernate-JIRA] Commented: (HHH-1) Optimize Hibernate for the bulk insertion of related entities
by Jay Erb (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1?page=com.... ]
Jay Erb commented on HHH-1:
---------------------------
We've found that this sorting algorithm is prohibitively long for insertions on the order of 100k records. I think we projected the loop count to be several trillion. We've developed a solution that provides more linear performance. The sort result is exactly the same; it just happens more quickly. I'd be happy to submit the change if anyone is interested.
> Optimize Hibernate for the bulk insertion of related entities
> -------------------------------------------------------------
>
> Key: HHH-1
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1
> Project: Hibernate3
> Issue Type: New Feature
> Components: core
> Environment: Hibernate 1.2, MySql 3.1
> Reporter: Bradley Leupen
> Assignee: Steve Ebersole
> Priority: Minor
> Fix For: 3.2.4, 3.3
>
> Attachments: bulk_insert.patch
>
>
> It is currently difficult to batch the creation of persistent entities that maintain associations with other entities.
> Add necessary api to hibernate to support the save or update of a collection of entities. An optimization can be applied in this scenario to group inserts / updates by entity class, or table. This will enable the hibernate engine to utilize batching if available, drastically improving performance over a network.
--
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
16 years, 6 months
[Hibernate-JIRA] Commented: (HHH-1961) Schema validation fails with floating point column in Oracle 10g
by Dean Pullen (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1961?page=c... ]
Dean Pullen commented on HHH-1961:
----------------------------------
"current workaround is to add a type-mapping in a reveng.xml file. "
Can you explain this in further detail? Thanks.
> Schema validation fails with floating point column in Oracle 10g
> ----------------------------------------------------------------
>
> Key: HHH-1961
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1961
> Project: Hibernate3
> Issue Type: Bug
> Affects Versions: 3.2.0.cr2
> Environment: 3.2 CR 2, Oracle 10g express edition release 2, Windows XP service pack 2, JDK 1.5.0_06
> Reporter: Daniel Dyer
>
> I have a table (created automatically by Hibernate) for mapping a double field. The table creation from Ant works fine but when starting up JBoss with the hibernate.hbm2ddl.auto property set to validate, I get the following exception:
> Caused by: org.hibernate.HibernateException: Wrong column type: percentage, expected: double precision
> at org.hibernate.mapping.Table.validateColumns(Table.java:219)
> at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:965)
> at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)
> at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:296)
> at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
> at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:414)
> at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:575)
> at org.hibernate.ejb.Ejb3Configuration.createContainerEntityManagerFactory(Ejb3Configuration.java:245)
> at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:108)
> at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:260)
> ... 127 more
> Doing a "desc" on the table reveals that the column is of type FLOAT with a length of 22.
> I think this may be related to issue HHH-1566 or HHH-1008.
--
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
16 years, 6 months
[Hibernate-JIRA] Created: (HHH-2811) ScrollableResults.next() generates Exception when no records were found and ScrollMode.FORWARD_ONLY is used
by Simon Jongsma (JIRA)
ScrollableResults.next() generates Exception when no records were found and ScrollMode.FORWARD_ONLY is used
-----------------------------------------------------------------------------------------------------------
Key: HHH-2811
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2811
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.0.ga
Environment: Oracle database 9.2.0.5.0; Oracle jdbc driver 10.2.0.2.0; JBoss 4.0.4.GA; Hibernate 3.2.0.ga
Reporter: Simon Jongsma
When using ScrollableResults with ScrollMode.FORWARD_ONLY
i could not locate a way to test (without triggering an exception) if there are any records found.
If the set is empty the next() function generates (on first call) a
GenericJDBCException: "could not perform sequential read of results (forward)".
It should return the boolean false value instead.
When there are data found the next() function will work ok &
also will correctly return false when reaching the end of the set.
A workaround (kludge) is to catch the Exception like this:
ScrollableResults foundRecs = query.scroll(ScrollMode.FORWARD_ONLY);
try {
boolean found = foundRecs.next();
} catch (GenericJDBCException e) {
if (e.getMessage().equalsIgnoreCase("could not perform sequential read of results (forward)")) {
found = false;}
else throw new DatabaseException(e.getMessage(), e);
}
if (found) ....
--
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
16 years, 6 months