[Hibernate-JIRA] Commented: (HHH-980) FetchMode.SELECT javadoc wrong
by Gabriel Falkenberg (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-980?page=co... ]
Gabriel Falkenberg commented on HHH-980:
----------------------------------------
The two Jiira issues about FetchMode.SELECT (this one and HHH1211) seems to imply that maybe the documentation needs to be updated after all. The javadoc at http://www.hibernate.org/hib_docs/core/api/org/hibernate/FetchMode.html says:
SELECT
Fetch eagerly, using a separate select. Equivalent to fetch="select".
LAZY
Deprecated. use FetchMode.SELECT
Fetch lazily. Equivalent to outer-join="false".
So FetchMode.SELECT is eager but it should also be used instead of FetchMode.LAZY which is Lazy, what gives? Am I interpreting the words in the wrong way? Reading the above statement about FetchMode.SELECT makes me think that the following code should load a Foo-object with one select and the associated "bars" in another select:
Foo getFooWithBarsBySomeProp(String propValue)
{
Criteria criteria = getSession().createCriteria(Foo.class);
criteria.add(Restrictions.eq("someProp", propValue));
criteria.setFetchMode("bars", FetchMode.SELECT);
return (Foo) criteria.uniqueResult();
}
But when I run this and logs the SQL I can see that only one select is performed. It would be very helpful it this could be elaborated on in the documentation.
> FetchMode.SELECT javadoc wrong
> ------------------------------
>
> Key: HHH-980
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-980
> Project: Hibernate3
> Issue Type: Bug
> Components: documentation
> Affects Versions: 3.1 beta 2
> Reporter: Dave Brondsema
> Priority: Minor
>
> FetchMode.SELECT says "Fetch eagerly, using a separate select." but it should say "Fetch lazily, using a separate select."
> This is quite misleading
--
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, 2 months
[Hibernate-JIRA] Commented: (HHH-1523) LazyInitializationError on enabling query cache...
by DK (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1523?page=c... ]
DK commented on HHH-1523:
-------------------------
We are encountering this issue since upgrading to hibernate 3.2.6. Please help do a proper patch, the workaround is so ugly. Is anyone addressing this?
Thanks,
D
> 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, 2 months
[Hibernate-JIRA] Created: (HHH-3251) EJB query UPDATE with java.sql.Timestamp
by Ralf Alt (JIRA)
EJB query UPDATE with java.sql.Timestamp
----------------------------------------
Key: HHH-3251
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3251
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.3.0.CR1
Environment: MS SQL 2005, java version "1.6.0_05", Sun Java System Application Server 9.1_01 (build b09d-fcs)
Hibernate 3.3.2.GA
Reporter: Ralf Alt
Priority: Critical
Entity bean with Timestamp field.
@Version
@Column(name="modtime",nullable=false,insertable=false,updatable=true)
protected Timestamp getModificationtimeTS() {
return myModTime;
}
protected void setModificationtimeTS(Timestamp timestamp) {
myModTime = timestamp;
}
EJBQuery: "UPDATE ADRESS.class.getName() set name = :_name, modificationtimeTS = :_modtime where id = :_id"
Query qry = entityMgr.createQuery( query )
.setParameter( "_name", "Newer" )
.setParameter( "_modtime", new Timestamp( System.currentTimeMillis() ))
.setParameter( "_id", 1 );
The generated SQL
declare @p1 int
set @p1=NULL
exec sp_prepexec @p1 output,N'@P0 nvarchar(4000),@P1 datetime',N'update ADRESS set name=@P0, modtime=@P1 where id=@P2',N'Newer',''2008-04-24 16:14:17:490'',1
select @p1
The error is in the time stampformat for the sql server (syntax error in the near of '2008').
--
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, 2 months