[Hibernate-JIRA] Created: (HHH-3938) One-To-One Filter Applied, Non-Lazy Fetch Problem
by Sandeep Vaid (JIRA)
One-To-One Filter Applied, Non-Lazy Fetch Problem
-------------------------------------------------
Key: HHH-3938
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3938
Project: Hibernate Core
Issue Type: Improvement
Components: core
Affects Versions: 3.3.1
Reporter: Sandeep Vaid
Priority: Critical
Suppose i have one-to-one association between Product and ProductBasic. and we have applied filter on ProductBasic Class.
I have applied this filter as in Java side we have one-to-one relationship between Product and ProductBasic BUT at database side
we have one-to-many relationship between PRODUCT and PRODUCTBASIC. and we apply a condition (STARTTIME < CURRETTIME < ENDTIME)
while fetching PRODUCTBASIC, and this will always give me one record out of many.
So i have put this condition as filter in ProductBasic class.
In current hibernate, one-to-one associations are always non-lazily fetched. Moreover it doesn't apply filter conditions.
I understand that it can;t apply filter condition as some filter parameter must be provided at runtime and
user may not provide them (as he is not asking for ProductBasic)... Also in this case, proper proxy can't be created as
until we apply the filter criteria, we won't get one ProductBasic row (among many)..
I think hibernate code should be changed so that if a filter is declared on the associated class (ProductBasic in our case),
hibernate should return null for ProductBasic.
--
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-4866) Insert trying to insert values in the wrong order
by Neil Stickels (JIRA)
Insert trying to insert values in the wrong order
-------------------------------------------------
Key: HHH-4866
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4866
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.1
Environment: Using Hibernate 3.3.1 in JBoss 5.0.0, connecting to a MySQL 5.0 database
Reporter: Neil Stickels
It appears for all of my inserts where I have multiple parameters of the same type, it will mix up the order.
I am pretty new to Hibernate, so possibly I have something wrong. Here are what I think are the relevant files:
StoreBrand.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jan 10, 2010 12:38:41 AM by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
<class name="com.shopperapp.dao.StoreBrand" table="STORE_BRANDS" catalog="shopper_app">
<composite-id name="id" class="com.shopperapp.dao.StoreBrandId">
<key-property name="storeId" type="int">
<column name="STORE_ID" />
</key-property>
<key-property name="brandId" type="int">
<column name="BRAND_ID" />
</key-property>
</composite-id>
<many-to-one name="brand" class="com.shopperapp.dao.Brand" update="false" insert="false" fetch="select">
<column name="BRAND_ID" not-null="true" />
</many-to-one>
<many-to-one name="store" class="com.shopperapp.dao.Store" update="false" insert="false" fetch="select">
<column name="STORE_ID" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
Bean calling the persistence code:
StoreBrand sb = new StoreBrand(sbid, brand, store);
StoreBrandHome sbHome = new StoreBrandHome();
sbHome.persist(sb);
StoreBrandHome which does the persistence:
public void persist(StoreBrand transientInstance) {
log.debug("persisting StoreBrand instance");
try {
sessionFactory.getCurrentSession().beginTransaction();
System.out.println("trying to persist store_id "+transientInstance.getStore().getId()+" and brand_id "+transientInstance.getBrand().getId());
sessionFactory.getCurrentSession().persist(transientInstance);
sessionFactory.getCurrentSession().getTransaction().commit();
log.debug("persist successful");
} catch (RuntimeException re) {
log.error("persist failed", re);
throw re;
}
}
As you can see, I have a debug statement before the insert showing the store_id and the brand_id that I am trying to persist. When I turn on the debug, this is what I see in the server.log:
2010-01-30 20:34:37,194 DEBUG [org.hibernate.jdbc.ConnectionManager] (http-0.0.0.0-8080-2) opening JDBC connection
2010-01-30 20:34:37,195 INFO [STDOUT] (http-0.0.0.0-8080-2) trying to persist store_id 1 and brand_id 9
2010-01-30 20:34:37,195 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] (http-0.0.0.0-8080-2) generated identifier: component[storeId,brandId]{brandId=1, storeId=9}, using strategy: org.hibernate.id.Assigned
2010-01-30 20:34:37,195 DEBUG [org.hibernate.transaction.JDBCTransaction] (http-0.0.0.0-8080-2) commit
2010-01-30 20:34:37,195 DEBUG [org.hibernate.pretty.Printer] (http-0.0.0.0-8080-2) listing entities:
2010-01-30 20:34:37,195 DEBUG [org.hibernate.pretty.Printer] (http-0.0.0.0-8080-2) com.shopperapp.dao.StoreBrand{id=component[storeId,brandId]{brandId=1, storeId=9}, store=com.shopperapp.dao.Store#1, brand=com.shopperapp.dao.Brand#9}
2010-01-30 20:34:37,195 DEBUG [org.hibernate.jdbc.AbstractBatcher] (http-0.0.0.0-8080-2) about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2010-01-30 20:34:37,195 DEBUG [org.hibernate.SQL] (http-0.0.0.0-8080-2) insert into shopper_app.STORE_BRANDS (STORE_ID, BRAND_ID) values (?, ?)
2010-01-30 20:34:37,195 INFO [STDOUT] (http-0.0.0.0-8080-2) Hibernate: insert into shopper_app.STORE_BRANDS (STORE_ID, BRAND_ID) values (?, ?)
2010-01-30 20:34:37,198 DEBUG [org.hibernate.jdbc.AbstractBatcher] (http-0.0.0.0-8080-2) Executing batch size: 1
2010-01-30 20:34:37,211 DEBUG [org.hibernate.jdbc.AbstractBatcher] (http-0.0.0.0-8080-2) about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2010-01-30 20:34:37,215 DEBUG [org.hibernate.transaction.JDBCTransaction] (http-0.0.0.0-8080-2) committed JDBC Connection
You can see in the log, that the debug here says that it should be store_id 1 and brand_id 9, but in the debug statements around this, and when it actually does the insert, it reverses these, and inserts it as store_id 9 and brand_id 1.
--
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-4865) criteria on association w/ fetch=join, get n+1 queries
by Kevin Howard (JIRA)
criteria on association w/ fetch=join, get n+1 queries
------------------------------------------------------
Key: HHH-4865
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4865
Project: Hibernate Core
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.2.7
Environment: Hibernate 3.2.7.ga
Reporter: Kevin Howard
Priority: Minor
When I specify a restriction on an one-to-many association in a criteria query, Hibernate executes n+1 queries even though the first query is joining the two tables correctly with an inner join. This happens if I use createAlias or createCriteria to specify the restriction on the association. If I don't specify a restriction on the association then I do not get n+1 queries and the association is populated. This seems like a bug as all the data is returned in the initial query and the following queries are not needed. I posted this in the forum (https://forum.hibernate.org/viewtopic.php?f=1&t=1002270) with no response.
Criteria Query:
final DetachedCriteria criteria = DetachedCriteria.forClass(A.class);
criteria.add(Restrictions.eq("column1", value1))
.createAlias("someSetofB", "h")
.add(Restrictions.in("h.code", new String[] {"A","B","C"}));
final List<A> list = getHibernateTemplate().findByCriteria(criteria);
Association Mapping:
<set name="someSetofB" lazy="false" fetch="join">
<key>
<column name="SOME_ID" />
</key>
<one-to-many class="B" />
</set>
SQL:
select ..(every column from A and B).. from A this_ inner join B h1_ on this_.SOME_ID=h1_.SOME_ID where this_.COLUMN_ONE=? and h1_.CODE in (?, ?, ?)
select .... from B someSetOfB0_ where someSetOfB0_.SOME_ID=?
select .... from B someSetOfB0_ where someSetOfB0_.SOME_ID=?
..... selects for as many A's returned by first query
--
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-16) Explicit joins on unrelated classes
by Steve Ebersole (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-16?page=com... ]
Steve Ebersole commented on HHH-16:
-----------------------------------
http://docs.jboss.org/hibernate/stable/core/reference/en-US/html_single/#...
14.3. Associations and joins
{quote}
You may supply extra join conditions using the HQL with keyword.
from Cat as cat
left join cat.kittens as kitten
with kitten.bodyWeight > 10.0
{quote}
Could it be *better* documented? Sure, like later on there is only a brief warning about using fetch w/ with but its a serious thing to avoid.
If you want to step up and help improve the docs, please do :)
> Explicit joins on unrelated classes
> -----------------------------------
>
> Key: HHH-16
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-16
> Project: Hibernate Core
> Issue Type: New Feature
> Components: core
> Affects Versions: antlr-rework
> Environment: Any
> Reporter: David Lloyd
> Assignee: Steve Ebersole
> Fix For: antlr-rework
>
>
> It would be nice to be able to do explicit joins on unrelated classes with HQL:
> (hope this renders correctly)
> select empl, phone
> from org.example.Employee empl
> left outer join org.example.PhoneBook phone
> on phone.lastName = empl.lastName
> and phone.firstName = empl.firstName
> where empl.salaryGrade > 10
> Note that this would also implicity solve HB-1089 because you could list join criteria that match what Hibernate would have chosen anyway (i.e., list a many-to-one relationship as a criteria explicitly).
> Syntactically this could be disambiguated from the existing join syntax because the token after "join" is a class name rather than a property name.
--
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-16) Explicit joins on unrelated classes
by hugo (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-16?page=com... ]
hugo commented on HHH-16:
-------------------------
Ok, for the issue HB-1441 *there is a solution*. I never heard about the "WITH" keyword in the online documentation, but it appears to works perfectly as a criteria on the ON clause !
For instance one could generate the following (pseudo) SQL :
[...]
LEFT JOIN car AS customer_car ON car.brand_id = brand.id AND customer_car.color='yellow'
[...]
using the following (pseudo) HQL:
[...]
LEFT JOIN car.brand AS customer_car WITH customer_car.color='yellow'
[...]
Good to know ! It should be be added to the documentation ;) (Can I help here ?)
PS: sorry to hijack this issue, but I can't comment directly in HB-1441
> Explicit joins on unrelated classes
> -----------------------------------
>
> Key: HHH-16
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-16
> Project: Hibernate Core
> Issue Type: New Feature
> Components: core
> Affects Versions: antlr-rework
> Environment: Any
> Reporter: David Lloyd
> Assignee: Steve Ebersole
> Fix For: antlr-rework
>
>
> It would be nice to be able to do explicit joins on unrelated classes with HQL:
> (hope this renders correctly)
> select empl, phone
> from org.example.Employee empl
> left outer join org.example.PhoneBook phone
> on phone.lastName = empl.lastName
> and phone.firstName = empl.firstName
> where empl.salaryGrade > 10
> Note that this would also implicity solve HB-1089 because you could list join criteria that match what Hibernate would have chosen anyway (i.e., list a many-to-one relationship as a criteria explicitly).
> Syntactically this could be disambiguated from the existing join syntax because the token after "join" is a class name rather than a property name.
--
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-16) Explicit joins on unrelated classes
by hugo (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-16?page=com... ]
hugo commented on HHH-16:
-------------------------
The main need here is to be able to add criteria on the clause of an *outer* join ! Because in those cases the semantic of a criteria in the ON clause or in the WHERE clause is completely different.
Today it's not possible to do that, and thus some kind of queries can not be expressed in HQL.
I'm not sure the current issue will address that, but it appears HB-1441 clearly is the heart of the problem.
> Explicit joins on unrelated classes
> -----------------------------------
>
> Key: HHH-16
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-16
> Project: Hibernate Core
> Issue Type: New Feature
> Components: core
> Affects Versions: antlr-rework
> Environment: Any
> Reporter: David Lloyd
> Assignee: Steve Ebersole
> Fix For: antlr-rework
>
>
> It would be nice to be able to do explicit joins on unrelated classes with HQL:
> (hope this renders correctly)
> select empl, phone
> from org.example.Employee empl
> left outer join org.example.PhoneBook phone
> on phone.lastName = empl.lastName
> and phone.firstName = empl.firstName
> where empl.salaryGrade > 10
> Note that this would also implicity solve HB-1089 because you could list join criteria that match what Hibernate would have chosen anyway (i.e., list a many-to-one relationship as a criteria explicitly).
> Syntactically this could be disambiguated from the existing join syntax because the token after "join" is a class name rather than a property name.
--
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