[Hibernate-JIRA] Created: (HHH-4595) DDL export generates FK constraint before the essential unique constraint, and fails
by Chris Wilson (JIRA)
DDL export generates FK constraint before the essential unique constraint, and fails
------------------------------------------------------------------------------------
Key: HHH-4595
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4595
Project: Hibernate Core
Issue Type: Bug
Components: annotations
Affects Versions: 3.3.2
Environment: Core 3.3.2, with Annotations 3.4.0, on MySQL 5.0.51a-3ubuntu5.4.
Reporter: Chris Wilson
Attachments: HibernateJoinPropertyRefMultipleColumnsFails.java
With the attached test case, which defines some classes and tries to generate the DDL for them, Hibernate tries to generate the foreign key constraint before the unique constraint:
create table user_roles (id integer not null, role varchar(255), user_name varchar(255), project_id integer, site_id integer not null, primary key (id))
...
alter table user_roles add constraint FK73429949AACF5CB1 foreign key (project_id, site_id) references project_site (project_id, site_id)
MySQL doesn't allow this, generating the following error:
"Constraint 'FK73429949AACF5CB1' is invalid: there is no unique or primary key constraint on table '"ROOT"."PROJECT_SITE"' that matches the number and types of the columns in the foreign key."
And indeed there is none, because Hibernate hasn't added it yet:
create table project (id integer not null, primary key (id))
create table project_site (id integer not null, project_id integer, site_id integer, primary key (id))
create table site (id integer not null, primary key (id))
create table user_roles (id integer not null, role varchar(255), user_name varchar(255), project_id integer, site_id integer not null, primary key (id))
alter table project_site add constraint FK380054AD6E971B37 foreign key (project_id) references project
alter table project_site add constraint FK380054AD6E3AE95D foreign key (site_id) references site
alter table user_roles add constraint FK73429949AACF5CB1 foreign key (project_id, site_id) references project_site (project_id, site_id)
16:27:35,834 ERROR SchemaExport: schema export unsuccessful
org.hibernate.JDBCException: Error during DDL export
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:345)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:262)
at org.wfp.rita.datafacade.HibernateJoinPropertyRefMultipleColumnsFails.test(HibernateJoinPropertyRefMultipleColumnsFails.java:149)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.SQLException: Constraint 'FK73429949AACF5CB1' is invalid: there is no unique or primary key constraint on table '"ROOT"."PROJECT_SITE"' that matches the number and types of the columns in the foreign key.
--
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, 4 months
[Hibernate-JIRA] Created: (HHH-4597) Unhelpful error message with property-ref to non-existent property
by Chris Wilson (JIRA)
Unhelpful error message with property-ref to non-existent property
------------------------------------------------------------------
Key: HHH-4597
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4597
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.2
Environment: Hibernate 3.3.2 GA, annotations, MySQL 5.0.51a-3ubuntu5.4
Reporter: Chris Wilson
Attachments: HibernatePropertyRefNotFoundErrorMessageTest.java
When a mapping references a property in another mapping that doesn't exist, Hibernate gives an exception like this:
org.hibernate.MappingException: property-ref [projectSite] not found on entity [org.wfp.rita.dao.ProjectSite]
which doesn't give the most important information: where the reference came *from*. Without this, you have to hunt through all your mapping files looking for a property-ref to the table and property that doesn't exist.
Might I suggest an error message like this instead?
Association property [owner] of [org.wfp.rita.datafacade.HibernatePropertyRefNotFoundErrorMessageTest$House]
references unknown property [ssn] of [org.wfp.rita.datafacade.HibernatePropertyRefNotFoundErrorMessageTest$Person].
The attached test case reproduces the issue and tests for the new error message, please adjust to taste.
I know this is not a show-stopper but it's a major irritation and waste of time to have to figure out what this exception means and dig through all your mappings to find the problem.
Sorry I didn't create a patch, but Hibernate is not exactly simple to build. Unfortunately the referencing property (association) name is not immediately accessible during the second pass where this error is thrown, but I think it could be fixed using something like this:
ManyToOne.java:
public void createPropertyRefConstraints(Map persistentClasses) {
if (referencedPropertyName!=null) {
PersistentClass associationClass = (PersistentClass) persistentClasses.get(getAssociatedEntityName() );
String associationPropName;
for (Property prop : associationClass.getProperties())
{
if (prop.getValue() == this)
{
associationPropName = prop.getName();
break;
}
}
if (associationPropName == null) throw Exception(...)
PersistentClass pc = (PersistentClass) persistentClasses.get(getReferencedEntityName() );
try
{
Property property = pc.getReferencedProperty( getReferencedPropertyName() );
}
catch (MappingException e)
{
throw new MappingException("Association property [" +
associationPropName + "] of [" +
getAssociatedEntityName() + "] references unknown property [" +
getReferencedPropertyName() + "] of [" +
getReferencedEntityName() + "]", e);
}
Cheers, Chris.
--
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, 4 months
[Hibernate-JIRA] Created: (EJB-431) JPA/Hibernate on websphere 6.1
by pooja gupta (JIRA)
JPA/Hibernate on websphere 6.1
------------------------------
Key: EJB-431
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-431
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.4.0.GA
Environment: Oracle 10g, WebSphere Platform 6.1 [EJB3 6.1.0.19 cf190834.03] [BASE 6.1.0.19 cf190836.04] [WEB2FEP 1.0.0.1 web20835.6] [WEBSERVICES 6.1.0.19 cf190834.03] , OS - Windows XP, Version 5.1 build 2600 Service Pack 2
Reporter: pooja gupta
Priority: Critical
Attachments: jpa_hib_err.rtf, server-console.rtf
We are trying to use JPA/Hibernate for our database operations, application being deployed on WAS 6.1. Now when JPA provider is configured to use Websphere's default JPA provider or Open JPA, the things work. However, it fails to create the entity manager factory when the provider is changed to Hibernate. The exception thrown is not very specific.
Any help would be appreciated. We are using following jars
commons-collections.jar
commons-configuration-1.4.jar
commons-lang-2.3.jar
commons-logging-1.1.1.jar
dom4j.jar
hibernate3.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-core.jar
hibernate-entitymanager.jar
ojdbc14.jar
log4j.jar
--
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, 4 months
[Hibernate-JIRA] Created: (HHH-2142) PersistentMap.put(), remove() may return UNKNOWN object that can cause ClassCastException in client code
by Andrzej Miazga (JIRA)
PersistentMap.put(), remove() may return UNKNOWN object that can cause ClassCastException in client code
--------------------------------------------------------------------------------------------------------
Key: HHH-2142
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2142
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.0.cr5
Reporter: Andrzej Miazga
Here is some code in Hibernate 3.2.0cr5 that may cause this behaviour. I'm not sure if this is a bug but it surely affects the client code.
AbstractPersistentCollection:
protected Object readElementByIndex(Object index) {
if (!initialized) {
...
return persister.getElementByIndex( entry.getLoadedKey(), index, session, owner );
}
...
return UNKNOWN;
}
PersistentMap (extends AbstractPersistentCollection):
public Object put(Object key, Object value) {
if ( isPutQueueEnabled() ) {
Object old = readElementByIndex( key );
queueOperation( new Put( key, value, old ) );
return old;
}
...
So, there is a possibility to return UNKNOWN instance (MarkerObject) to the client code as the result of Map.put().
In version 3.1.3 this worked fine, but the implementation was different:
public Object put(Object key, Object value) {
Object old = isPutQueueEnabled() ?
readElementByIndex(key) : UNKNOWN;
if ( old==UNKNOWN ) {
write();
return map.put(key, value);
}
...
}
--
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, 4 months
[Hibernate-JIRA] Commented: (HHH-1361) creating temporary table for bulk delete will commit current transaction in managed environment such as J2EE
by Steve Ebersole (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1361?page=c... ]
Steve Ebersole commented on HHH-1361:
-------------------------------------
Again, my issue with this is that my own testing as well as the testing done by Jifeng Liu show this working as-is. So before I make any further changes I'd like to understand what is different in your server/driver setup that causes you to see different results.
> creating temporary table for bulk delete will commit current transaction in managed environment such as J2EE
> ------------------------------------------------------------------------------------------------------------
>
> Key: HHH-1361
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1361
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.1
> Environment: J2EE container; Oracle
> Reporter: Jifeng Liu
> Assignee: Steve Ebersole
> Fix For: 3.1.1
>
> Attachments: hibernate.cfg.xml, stacktrace.txt
>
>
> I have a table mapping with joined-subclass as following. When I execute bulk delete statement:
> session.createQuery( "delete from Job j where j.status = :status" )
> .setString( "status", pStatus )
> .executeUpdate()
> Hibernate will automatically create a temporary table called HT_Job to store job ids. This will cause current database transaction committed. Because I am using J2EE container managed transaction (CMT), this commit behavior is not good. And I also lose opportunity to rollback the transaction.
> <class name="com.senior.bll.shared.jobs.Job"
> table="job" rowid="rowid">
> <id name="id" column="job_id"/>
> <version name="updateDateTime" column="update_date_time" type="oracle_date"></version>
> <property name="type" column="job_type"/>
> <joined-subclass name="com.senior.bll.entity.constituent.messaging.schedules.MessageJob"
> table="message_job_data" >
> <key column="job_id" />
> <property name="queryId" column="query_id"/>
> </joined-subclass>
> </class>
--
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, 4 months
[Hibernate-JIRA] Commented: (HHH-1361) creating temporary table for bulk delete will commit current transaction in managed environment such as J2EE
by Francesco (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1361?page=c... ]
Francesco commented on HHH-1361:
--------------------------------
The problem doesn't seems resolved... looking at 3.2.6ga I still see the old behaviour.
Probably oracle dialects should be changed, as noted above, adding:
public boolean performTemporaryTableDDLInIsolation() {
return true;
}
here you can find a better description of the oracle weird commit (look at "Creating Strored Procedures"):
http://beehive.apache.org/docs/1.0.2/system-controls/jdbc/guide.html
> creating temporary table for bulk delete will commit current transaction in managed environment such as J2EE
> ------------------------------------------------------------------------------------------------------------
>
> Key: HHH-1361
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1361
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.1
> Environment: J2EE container; Oracle
> Reporter: Jifeng Liu
> Assignee: Steve Ebersole
> Fix For: 3.1.1
>
> Attachments: hibernate.cfg.xml, stacktrace.txt
>
>
> I have a table mapping with joined-subclass as following. When I execute bulk delete statement:
> session.createQuery( "delete from Job j where j.status = :status" )
> .setString( "status", pStatus )
> .executeUpdate()
> Hibernate will automatically create a temporary table called HT_Job to store job ids. This will cause current database transaction committed. Because I am using J2EE container managed transaction (CMT), this commit behavior is not good. And I also lose opportunity to rollback the transaction.
> <class name="com.senior.bll.shared.jobs.Job"
> table="job" rowid="rowid">
> <id name="id" column="job_id"/>
> <version name="updateDateTime" column="update_date_time" type="oracle_date"></version>
> <property name="type" column="job_type"/>
> <joined-subclass name="com.senior.bll.entity.constituent.messaging.schedules.MessageJob"
> table="message_job_data" >
> <key column="job_id" />
> <property name="queryId" column="query_id"/>
> </joined-subclass>
> </class>
--
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, 4 months