[Hibernate-JIRA] Commented: (HHH-879) Enable joining the same association twice with Criteria
by James Olsen (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-879?page=co... ]
James Olsen commented on HHH-879:
---------------------------------
WORKAROUND
I use extra 'query keys' (a term borrowed from a competing product) as shown below.
This first mapping is the standard one. In my case it's protected, FetchType.LAZY and ignores any data as I never use it to retrieve data directly. It's just metadata for a query key so that I have transitive closure for these objects in a distributed system but still have all the relationships defined for querying purposes. You could have this first mapping as a proper mapping if you want.
@OneToMany(targetEntity = TradeOrderAuditImpl.class, fetch = FetchType.LAZY, mappedBy = "tradeOrder")
protected Set<TradeOrderAudit> getTradeOrderAudits() {
return null;
}
protected void setTradeOrderAudits(Set<TradeOrderAudit> tradeOrderAudits) {
}
This second mapping is to the same entity. Again, it's just a query key. In this case it also happens to have a constraint which uniquely identifies the target object (making this suit a single purpose). This is completely optional, you could leave the @Where off and use criteria to constrain in the normal way (making it as general purpose as the standard mapping).
@OneToMany(targetEntity = TradeOrderAuditImpl.class, fetch = FetchType.LAZY, mappedBy = "tradeOrder")
@Where(clause="ORDER_ACTION_EN = 6")
protected Set<TradeOrderAudit> getFillTradeOrderAudit() {
return null;
}
protected void setFillTradeOrderAudit(Set<TradeOrderAudit> tradeOrderAudits) {
}
Now I can refer to both 'tradeOrderAudits' and 'fillTradeOrderAudit' which relate to the same table and use them in query restrictions and projections.
These query keys don't seem to affect performance too much. On merge hibernate thinks the collections have simply been dereferenced and ignores them (no cascading).
I rely on these a lot (more for the transitive-closure-with-full-relationship-metadata benefit) so it would actually be nice to have the notion of a 'query key' promoted to a first class item rather than this hack. Perhaps equivalents of the existing relationship annotations but with 'QK' prefixed and placed at the class level?
> Enable joining the same association twice with Criteria
> -------------------------------------------------------
>
> Key: HHH-879
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-879
> Project: Hibernate3
> 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
17 years, 9 months
[Hibernate-JIRA] Created: (EJB-349) EM Incorrectly throws EntityExistsException wrapping ConstraintViolationException on constraint violation during delete
by Derek Chen-Becker (JIRA)
EM Incorrectly throws EntityExistsException wrapping ConstraintViolationException on constraint violation during delete
-----------------------------------------------------------------------------------------------------------------------
Key: EJB-349
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-349
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.3.1.GA
Environment: Postgresql 8.2.7, Hibernate 3.2.4.GA, Hibernate EM 3.3.1.GA
Reporter: Derek Chen-Becker
When I attempt to delete an entity via a named query, and the entity has a foreign key constraint, the EM throws an EntityExistsException that wraps the real org.hibernate.exception.ConstraintViolationException:
INFO - Service request (GET) /org/removeEmail.html took 89 Milliseconds
WARN - SQL Error: 0, SQLState: 23503
ERROR - ERROR: update or delete on table "organization_email" violates foreign key constraint "fk_org_email" on table "organizations"
Detail: Key (id)=(1) is still referenced from table "organizations".
ERROR - EM Error
javax.persistence.EntityExistsException: org.hibernate.exception.ConstraintViolationException: could not execute update query
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:605)
at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:59)
I checked the source code for 3.3.1 and revision 14382 of org.hibernate.ejb.AbstractEntityManagerImpl.java has a "FIXME" message on line 612 that basically indicates that this is a known issue. I couldn't find an existing bug on it in JIRA, so I apologize if this is a dup. In any case, is there any way for the EM to determine that the attempted statement was a delete and not an insert/update?
--
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
17 years, 9 months
[Hibernate-JIRA] Commented: (HHH-468) MysqlDialect incorrectly maps java.lang.Boolean to SQL BIT
by Corey Lohman (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-468?page=co... ]
Corey Lohman commented on HHH-468:
----------------------------------
To get booleans working without custom code this alias may be useful (works for MySQL -> HBM -> Java tooling):
1) represent booleans with TINYINT(1)
2) Add to cfg tinyInt1isBit=true & transformedBitIsBoolean=true:
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.tinyInt1isBit">true</property>
<property name="hibernate.connection.transformedBitIsBoolean">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
3) if running hbm2hbmxml, hbm2cfgxml, hbm2java use jdbcconfiguration, not configuration
One version set this worked on: JDK 1.5.0_09, Connect/J 5.1.6, Hibernate 3.2, Tools 3.2.2b1
> MysqlDialect incorrectly maps java.lang.Boolean to SQL BIT
> ----------------------------------------------------------
>
> Key: HHH-468
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-468
> Project: Hibernate3
> Issue Type: Bug
> Affects Versions: 3.0.3
> Environment: Hibernate 3.0, MySQL.
> Reporter: Mark Matthews
> Assignee: Scott Marlow
>
> I didn't track down how java.lang.Boolean gets mapped to Types.BIT in hibernate, but you probably _don't_ want to map to "bit" like you do in MysqlDialect.
> "bit", according to SQL99 (it's not in the core standard, and the type was actually dropped for sql2k3) is a bitfield, not a boolean value. You can of course define a bit(1), but it is technically more correct for java.lang.Boolean to map to a SQL BOOLEAN for MySQL since we support a BOOLEAN and a BIT.
> It looks like the JDBC-3.0 guys ignored what the standard said, because in reality you'd want BIT to map to something like byte[], or java.util.BitSet if you were tracking how the SQL standard defines BIT.
> I'm guessing you probably want to map to "boolean", which the JDBC driver will automagically convert for you, as it silently maps to TINYINT(1) on the server side.
--
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
17 years, 9 months
[Hibernate-JIRA] Created: (HHH-3354) Add entity in one-to-many collection, auto-flush and remove entity does not remove the entity
by Pascal Perez (JIRA)
Add entity in one-to-many collection, auto-flush and remove entity does not remove the entity
---------------------------------------------------------------------------------------------
Key: HHH-3354
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3354
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.1
Environment: Observed on MySQL 5, unit tested on HSQLDB.
Reporter: Pascal Perez
Attachments: entities.zip
In plain English:
An Item may have multiple Comment (one-to-many). When adding two comments to an item, auto-flushing, and removing one item, Hibernate loses track of both comments and does not delete the removed comment. The cascading has "delete-orphan".
Hibernate behaves in two different ways depending on whether the removed comment entity holds a reference to the Item or not.
1) if it holds a reference: the Comment entity is not removed. The transaction commits silently.
2) if it does not hold a reference anymore (i.e. comment.item = null): The Comment entity is updated to have it's reference to Item set to NULL, but is not deleted. This creates zombie entities in the DB. This case is highlighted in the unit test below by forcing the relation to be not-null="true" triggering a DB constraint violation upon commit. Otherwise, Hibernate commits silently.
In unit tests (test is parameterized to handle cases 1 and 2):
@Test
public void addAutoFlushRemove() throws Exception {
autoFlushInTheMiddle(false);
}
@Test
public void addAutoFlushUnreferenceRemove() throws Exception {
autoFlushInTheMiddle(true);
}
private void autoFlushInTheMiddle(boolean commentToItemReference) {
// creating an item
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Item item = new Item();
session.save(item);
assertEquals(0, item.comments.size());
tx.commit();
session.close();
// reading back the item, add two comments, auto-flush, delete one
session = sessionFactory.openSession();
tx = session.beginTransaction();
item = (Item) session.get(Item.class, item.id);
Comment comment1 = new Comment(); comment1.item = item;
item.comments.add(comment1);
Comment comment2 = new Comment(); comment2.item = item;
item.comments.add(comment2);
// forcing an auto flush
session.createCriteria(Item.class).list();
item.comments.remove(comment1);
if (commentToItemReference) comment1.item = null;
tx.commit();
session.close();
// check that we have one comment
session = sessionFactory.openSession();
item = (Item) session.get(Item.class, item.id);
assertEquals(1, item.comments.size());
session.close();
}
--
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
17 years, 9 months
[Hibernate-JIRA] Commented: (HHH-1961) Schema validation fails with floating point column in Oracle 10g
by eric (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1961?page=c... ]
eric commented on HHH-1961:
---------------------------
Found a work around to this. We had a column defined as NUMBER(11,8) and we wanted it to map to a java Double and to get it to work we mapped it as this
@Column(name = "column_name", unique = false, nullable = true, insertable = true, updatable = true, precision = 11, scale=8, columnDefinition="NUMBER(11,8)")
and the validation did not complain. not sure if it does validate the column is defined correctly but we are happy that the validator does not complain
> 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
17 years, 9 months