[Hibernate-JIRA] Created: (HHH-3231) org.hibernate.id.enhanced.TableGenerator throws "IllegalArgumentException: alias not found: tbl" under Oracle
by Király Attila (JIRA)
org.hibernate.id.enhanced.TableGenerator throws "IllegalArgumentException: alias not found: tbl" under Oracle
-------------------------------------------------------------------------------------------------------------
Key: HHH-3231
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3231
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.6
Environment: Hibernate 3.2.6GA, Oracle 10g
Reporter: Király Attila
Attachments: hibernate_etg_ora.zip
org.hibernate.id.enhanced.TableGenerator always throws the following exception if I want to save a new object to Oracle:
java.lang.IllegalArgumentException: alias not found: tbl
at org.hibernate.sql.ForUpdateFragment.<init>(ForUpdateFragment.java:36)
at org.hibernate.dialect.Dialect.applyLocksToSql(Dialect.java:970)
at org.hibernate.id.enhanced.TableGenerator.configure(TableGenerator.java:194)
at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:104)
I attach an example to this case. The example is loosely based on the tutorial example, that comes with Hibernate. It contains a Person object that is saved to db using the enhanced.TableGenerator as id generator. To keep the zip small only the jars of jdbc driver are included, the jars needed from hibernate distribution are listed in lib/readme.txt.
The zip also contains a modified TableGenerator that works with Oracle. This version was made by forum user stomp and more information about it can be read here: http://forum.hibernate.org/viewtopic.php?t=980933
It changes the 194th row of TableGenerator from
this.query = dialect.applyLocksToSql( query, lockMap, CollectionHelper.EMPTY_MAP );
to
this.query = dialect.applyLocksToSql( query, lockMap, Collections.singletonMap("tbl", new String[] {valueColumnName}) );
--
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, 3 months
[Hibernate-JIRA] Created: (HHH-3771) Best pactice for equals implementation?
by Samppa Saarela (JIRA)
Best pactice for equals implementation?
---------------------------------------
Key: HHH-3771
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3771
Project: Hibernate Core
Issue Type: New Feature
Components: core, documentation
Reporter: Samppa Saarela
When domain model contains even one lazy reference to an object, default equals fails when it's compared to a) the actual implementation returned by Session.get/load or b) other proxies (at least of different supertype). Overriding equals on a class that uses surrogate id is not that simple. However there is a simple solution to this problem:
In domain class, override equals like this:
public boolean equals(Object obj) {
return this == getImplementation(obj);
}
public static Object getImplementation(Object obj) {
if (obj instanceof HibernateProxy) {
return ((HibernateProxy) obj).getHibernateLazyInitializer().getImplementation();
} else {
return obj;
}
}
This should result always in comparing object references of actual instances and thus preserve symmetry.
It's understandable that you don't wan to publish that kind of getImplementation utility e.g. in Hibernate, but maybe you could support this more directly by implementing
Hibernate.equals(Object o1, Object o2)
--
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, 3 months
[Hibernate-JIRA] Created: (HHH-3908) Expose way to fully control fetching in native-sql queries in API
by Steve Ebersole (JIRA)
Expose way to fully control fetching in native-sql queries in API
-----------------------------------------------------------------
Key: HHH-3908
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3908
Project: Hibernate Core
Issue Type: New Feature
Components: core
Reporter: Steve Ebersole
Fix For: 3.5
Currently, in order to fully control fetching in native-sql queries, users must revert to using a named sql query (at least the xml, not sure if the annotations variety supports as well). We alreasy have all the objects/contracts in place to handle this for the named queries, just need to clean-up and properly document them.
The current API calls to deal with this are the overloaded SQLQuery#addJoin methods. Ideally I'd see these changed to return the representation of the join-fetch to be configured; but addJoin already defines a return : the query itself :( So probably we will need new methods like addFetch:
1) public JoinFetch addFetch(String alias, String ownerAlias, String ownerProperty)
2) public JoinFetch addFetch(String alias, String ownerAlias, String ownerProperty, LockMode lockMode)
interface JoinFetch {
public void addPropertyMapping(String propertyName, String sqlAlias);
}
This can be expanded to the "root returns" as well (currently the overloaded #addEntity methods):
public RootReturn addRoot(String alias, Class entityClass)
etc...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQLQuery query = session.createSQLQuery(
"select c.cust_id as cid, " +
" c.cust_name as cname, " +
" o.order_id as oid, " +
" o.order_num as onum " +
" from customer c " +
" inner join orders o " +
" on c.cust_id = o.cust_id"
);
query.addRoot( "c", Customer.class )
.addPropertyMapping( "id", "cid" )
.addPropertyMapping( "name", "cname" );
query.addFetch( "o", "c", "orders" )
.addPropertyMapping( "id", "oid" )
.addPropertyMapping( "orderNumber", "onum" );
...
--
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, 3 months
[Hibernate-JIRA] Created: (HHH-3609) Invalid list re-ordering with IndexColumn and OneToMany association
by Martin Kovacik (JIRA)
Invalid list re-ordering with IndexColumn and OneToMany association
-------------------------------------------------------------------
Key: HHH-3609
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3609
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.1
Environment: Hibernate 3.3.1, Hibernate Tools 3.2.0, H2 database 1.0.69
Reporter: Martin Kovacik
I want to map unidirectional OneToMany ordered list using annotations. My mapping is:
public class Invoice {
// ...
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(
name = "INVOICE_ITEM",
joinColumns = {@JoinColumn(name = "invoice_id")},
inverseJoinColumns = {@JoinColumn(name = "item_id")}
)
@Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@IndexColumn(name = "item_order")
private List<Item> items = new ArrayList<Item>();
}
The mapping of Item is not important here because I just want the association from Invoice to collection of Items to be unidirectional.
The problem what hbm2ddl generates:
create table INVOICE_ITEM (
invoice_id int8 not null,
item_id int8 not null,
item_order int4 not null,
primary key (invoice_id, item_order),
unique (item_id)
);
alter table INVOICE_ITEM
add constraint FK89837AD3EDA329D
foreign key (item_id)
references ITEM;
alter table INVOICE_ITEM
add constraint FK89837AD76A8E2D7
foreign key (invoice_id)
references INVOICE;
Another problem is how hibernate handles list re-ordering. If I want to change the item order (by manipulating invoice.items list) and then persist the changes hibernate tries to execute following sql:
update
INVOICE_ITEM
set
item_id=2
where
invoice_id=1
and item_order=0
update
INVOICE_ITEM
set
item_id=1
where
invoice_id=1
and item_order=1
However this causes DB to complain about unique item_id constraint (which was generated by hibernate). IMHO hibernate should update just the item_order column.
I think that this bug is related to ANN-679 (http://opensource.atlassian.com/projects/hibernate/browse/ANN-679).
--
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, 3 months
[Hibernate-JIRA] Created: (HHH-2269) Many-to-one cascade fails with TransientObjectException if the inverse collection is marked CascadeType.DELETE_ORPHAN
by Edward Costello (JIRA)
Many-to-one cascade fails with TransientObjectException if the inverse collection is marked CascadeType.DELETE_ORPHAN
---------------------------------------------------------------------------------------------------------------------
Key: HHH-2269
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2269
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.0.cr2, 3.2.1
Environment: Using hibernate annotations.
Reporter: Edward Costello
Attachments: TestBidirectionalCascade.java
When both a many-to-one (child) and it's inverse one-to-many collection (on parent) are cascading. Attempting to save a child directly and cascade the save to the parent throws a TransientObjectException if the parent's collection is mapped CascadeType.DELETE_ORPHAN. For Example, with the classes below:
@Entity
public class Parent {
@OneToMany(mappedBy = "parent")
@Cascade(value = {CascadeType.ALL, CascadeType.DELETE_ORPHAN})
Set<DeleteOrphanChild> deleteOrphanChildren;
}
@Entity
public class DeleteOrphanChild {
@ManyToOne
@Cascade(value = CascadeType.ALL)
Parent parent;
}
Calling session.save() with an instance of the parent will cascade the save to the child as expected. However, calling save on an instance of the child will throw the TransientObjectException below while attempting to cascade the save to the parent.
org.hibernate.TransientObjectException: cascade.test.TestBidirectionalCascade$DeleteOrphanChild
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
at org.hibernate.collection.AbstractPersistentCollection.getOrphans(AbstractPersistentCollection.java:889)
at org.hibernate.collection.PersistentSet.getOrphans(PersistentSet.java:51)
at org.hibernate.engine.CollectionEntry.getOrphans(CollectionEntry.java:350)
at org.hibernate.engine.Cascade.deleteOrphans(Cascade.java:336)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:318)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:437)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:326)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:509)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:501)
at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:134)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:412)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:261)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:537)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:525)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:521)
If the DELETE_ORPHAN cascade is removed the save works fine. The attached test case runs against an in memory HSQLDB database. It contains 4 tests, the second test (testSaveChildDeleteOrphan) fails showing the above exception. The other three pass showing that cascading from the parent works and that cascading in both directions remove if the DELETE_ORPHAN cascade is removed.
We've only tested this with annotations, we haven't tried to reproduce it using hibernate mapping files.
--
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, 3 months