[Hibernate-JIRA] Commented: (HHH-1657) hql update generate wrong sql with joined subclass hierarcy
by Paul Giblock (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1657?page=c... ]
Paul Giblock commented on HHH-1657:
-----------------------------------
I am affected by this problem as well. A simple "update Child c set c.field = value where c.id in (:cids)" is causing the issue. In this case, the c.id field is the super class's Id.
I am updating 100 or so records. It sucks having to go back to SQL, and it is even worse having to do 100+ queries when individually merging the records.
It is almost insulting that a bug like this would be left open for over three years. If Hibernate cannot support simple updates, then the executeUpdate() function should just be removed.
> hql update generate wrong sql with joined subclass hierarcy
> -----------------------------------------------------------
>
> Key: HHH-1657
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1657
> Project: Hibernate Core
> Issue Type: Bug
> Components: query-hql
> Environment: Hibernate 3.2.0cr1, Hibernate 3.1.3
> Reporter: Alexey Romanchuk
> Assignee: Gail Badner
>
> Let suppose that we have two joined subclass entities: Parent (id PK) and Child (id PK) that mapped with joined subclass method.
> When I try to update Child by id with hql:
> update Child c set c.field = 'value' where c.id = 1234
> hibernate generates joined tables like
> insert into HT_parent select child0_.id as id from child child0_ inner join parent child0_1_ on child0_.id=child0_1_.id wher id in = 1234
> look at last condition. hibernate use id WITH OUT tables alias that cause sql exception: column reference "id" is ambiguous
--
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
14 years, 11 months
[Hibernate-JIRA] Commented: (HHH-879) Enable joining the same association twice with Criteria
by Chris Wilson (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-879?page=co... ]
Chris Wilson commented on HHH-879:
----------------------------------
I tried to work around this as suggested by creating more associations. In my case there were logically distinct associations that I could use for querying against, which also simplified the use of criteria, so the effect on code readability was not too bad.
However I did struggle because my additional associations caused the dreaded MappingException:
{quote}
org.hibernate.MappingException: Repeated column in mapping for entity: org.wfp.rita.dao.Movement column: request_line_id (should be mapped with insert="false" update="false")
{quote}
This is because apparently, if your OneToMany associations are not declared as Inverse, Hibernate Annotations CollectionBinder silently adds {{Backref}} properties which are marked as insertable but not updatable:
{code}
if ( !collection.isInverse()
&& !collection.getKey().isNullable() ) {
// for non-inverse one-to-many, with a not-null fk, add a backref!
String entityName = oneToMany.getReferencedEntityName();
PersistentClass referenced = mappings.getClass( entityName );
Backref prop = new Backref();
prop.setName( '_' + fkJoinColumns[0].getPropertyName() + "Backref" );
prop.setUpdateable( false );
{code}
The easy way around this seems to be to make the collections inverse. However, you can't just do this with annotations, because there's no way to set it directly. it's true for mapped associations and false otherwise (see how {{CollectionBinder.bind() calls setInverse(...)}}). I'm not sure why inversion is not the default for OneToMany associations, which are "usually" managed from the Many side (the other side) in any case.
I didn't really want to reuse the mapping from the other class, as it's logically inconsistent to have three distinct sets mapped by the same property on the other side, but nor did I want to create three duplicate mappings to work around this bug, so I'm reusing the mapping for now and hoping that it will work.
I'm mainly commenting here because this error was not easy to track down, and I wanted to make it easier for others in future, and to provide guidance to those working around this bug by adding associations.
> Enable joining the same association twice with Criteria
> -------------------------------------------------------
>
> Key: HHH-879
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-879
> Project: Hibernate Core
> Issue Type: Improvement
> Components: core
> Reporter: Vladimir Bayanov
>
> Make double joining the same association with Criteria.createCriteria possible. See: http://forum.hibernate.org/viewtopic.php?t=931249
--
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
14 years, 11 months