[Hibernate-JIRA] Created: (BVAL-213) Convert persistence storage exception into Bean Validation exceptions
by Emmanuel Bernard (JIRA)
Convert persistence storage exception into Bean Validation exceptions
---------------------------------------------------------------------
Key: BVAL-213
URL: http://opensource.atlassian.com/projects/hibernate/browse/BVAL-213
Project: Bean Validation
Issue Type: New Feature
Components: spec-general
Reporter: Emmanuel Bernard
This is not a problematic of Bean Validation per se but one of the issue people are facing is inconsistency in constraint reporting.
For example, the database can raise a some kind of unique constraint exception (specific to each vendor usually). It would be ideal to get it converted into a @Unique constraint exception as defined by Bean Validation.
Said differently by Christian
{code}I'd rather see improvement of message propagation/mapping when an integrity rule inside the database has been violated. Like, turning a fatal database transaction exception (JDBCException wrapped etc.) into a clean error message, with a strong and stable mapping across DBMS products. If a UNIQUE constraint has been violated at the database level, I'd like to catch it and turn it into a Bean Validation error for my client.
We have discussed this >5 years ago and at that time there was just no way to really guarantee that a JDBCException can tell you what the real cause of the problem was. Nobody standardized or required that the catalog name of the violated constraint is included so you couldn't map it. Maybe that's possible now. If not, at least the generic ConstraintViolationException should be an SPI of Bean Validation that JPA providers can throw.{code}
--
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, 9 months
[Hibernate-JIRA] Created: (HHH-5488) Hibernate fails with two kinds of exceptions on a compsite-key join table that references two composite keys (one column shared by both foreign keys)
by Karsten Wutzke (JIRA)
Hibernate fails with two kinds of exceptions on a compsite-key join table that references two composite keys (one column shared by both foreign keys)
-----------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-5488
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5488
Project: Hibernate Core
Issue Type: Bug
Components: annotations, core, entity-manager
Affects Versions: 3.6.0.Beta2, 3.5.4
Environment: Windows 7 64bit, localhost, Tomcat 6, embedded JBoss, Hibernate 3.5.4 and 3.6.0 Beta2, MySQL 5.1.46
Reporter: Karsten Wutzke
Priority: Blocker
Hibernate fails with two kinds of exceptions on a compsite-key join table that references two composite keys (one column shared by both foreign keys): see ZipArea.java and PostAddress.java inside the attached file
1. When having both entity classes use the annotations as they should be (ZipArea having @Entity and @Table, PostAddress association having @ManyToOne and @JoinColumns) then I get:
18.08.2010 18:22:51 org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet Geo Info Test Servlet as unavailable
18.08.2010 18:22:51 org.apache.catalina.core.StandardContext loadOnStartup
SCHWERWIEGEND: Servlet /geoinfotest threw load() exception
org.hibernate.MappingException: Unable to find column with logical name: state_code in ZipAreas
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:573)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:125)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:110)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1618)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1541)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1457)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1413)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1453)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1081)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:275)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:359)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at geoinfotest.GeoInfoTestServlet.<init>(GeoInfoTestServlet.java:16)
...
This is the most constant and frequent error. Note though, when I removed all the INDEXes from the database it sometimes happens that Hibernate can't find the column in Cities:
18.08.2010 19:37:43 org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet Geo Info Test Servlet as unavailable
18.08.2010 19:37:43 org.apache.catalina.core.StandardContext loadOnStartup
SCHWERWIEGEND: Servlet /geoinfotest threw load() exception
org.hibernate.MappingException: Unable to find column with logical name: state_code in Cities
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:573)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:125)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:110)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1618)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1541)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1457)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1413)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1453)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1081)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:275)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:359)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at geoinfotest.GeoInfoTestServlet.<init>(GeoInfoTestServlet.java:16)
...
2. When outcommenting PostAddress's @ManyToOne and @JoinColumns on zipArea and leaving @Entity and @Table on ZipArea class, I get the following exception:
18.08.2010 18:05:02 org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet Geo Info Test Servlet as unavailable
18.08.2010 18:05:02 org.apache.catalina.core.StandardContext loadOnStartup
SCHWERWIEGEND: Servlet /geoinfotest threw load() exception
org.hibernate.AnnotationException: referencedColumnNames(country_code, state_code, name) of geoinfotest.ZipArea.city referencing geoinfotest.City not mapped to a single property
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:204)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:110)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1618)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1541)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1457)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1413)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1453)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1081)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:275)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:359)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at geoinfotest.GeoInfoTestServlet.<init>(GeoInfoTestServlet.java:16)
...
I have no idea what's going on. The special situation of the ZipAreas join table is that it references country_code of both tables. As a result, I have only *one* country_code column, which is used twice by ZipArea's foreign keys. Maybe that's confusing Hibernate. I can only guess. The strange thing is that Hibernate fails with City not being mapped to a single property *or* not being able to map state_code. My assumption is that Hibernate gobbles on that special design in conjunction with indexes. Just guessing though.
Here's my original forum post: https://forum.hibernate.org/viewtopic.php?f=1&t=1006411
The DB design can be viewed here: http://www.kawoolutions.com/media/geoinfo.pdf
I have attached a ZIP of the test project including an Ant build script (including deploy-local, undeploy-local, and redeploy-local targets using the Tomcat deployment tasks). I outcommented the Tomcat deploy task setup and targets.
Use "ant war" to build the distribution WAR file. I also put a MySQL DDL script into the db dir, including the above PDF, and a MySQL Workbench model. The example doesn't need data to fail. The DB name is "geoinfo". Just set your MySQL DB username and password in xml/persistence.xml (I think it's not even needed).
--
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, 9 months
[Hibernate-JIRA] Created: (METAGEN-54) XML-only field access type Set attribute not generated
by Martijn Blankestijn (JIRA)
XML-only field access type Set attribute not generated
------------------------------------------------------
Key: METAGEN-54
URL: http://opensource.atlassian.com/projects/hibernate/browse/METAGEN-54
Project: Hibernate Metamodel Generator
Issue Type: Bug
Components: processor
Affects Versions: 1.1.1.Final
Environment: maven 3.0.2
Java: java version "1.6.0_22", Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Uname: Linux xxx 2.6.32-28-generic-pae #55-Ubuntu SMP Mon Jan 10 22:34:08 UTC 2011 i686 GNU/Linux
Reporter: Martijn Blankestijn
Assignee: Hardy Ferentschik
Attachments: 0001-XML-only-field-access-type-Set-attribute-not-generat.patch
I have a xml-only mapping with no target-entity attribute specified on collections. For the collections generics were used, so type information was available. The collections were not generated by the generator in the meta-model classes.
I have checked out the current version of the source from Git and made the changes (testcases and solution). You find these files attached to this bugreport. It is not a very 'clean' solution yet, but I wanted to shared the bug and possible solution first.
When I run maven just after checkout I had 4 failing testcases:
testAccessTypeForXmlConfiguredEmbeddables(org.hibernate.jpamodelgen.test.mixedmode.MixedConfigurationTest)
testDefaultAccessTypeApplied(org.hibernate.jpamodelgen.test.mixedmode.MixedConfigurationTest)
testExplicitXmlConfiguredAccessTypeApplied(org.hibernate.jpamodelgen.test.mixedmode.MixedConfigurationTest)
testMixedConfiguration(org.hibernate.jpamodelgen.test.mixedmode.MixedConfigurationTest)
I still had these 4 failing testcase with my solution and I have not investigated this further.
In my search for the answer (error in my mapping, incorrect understanding of the generator or a bug in the Generator) I found a couple of points I got confused about.
First is that the access type on the XML entity was not set if it was specified only on the entity (not in the persistence unit default or on the collection itself). It then defaulted to METHOD (a.k.a. property access)
In XmlMetaEntity (line 542)
return TypeUtils.getElementKindForAccessType( accessTypeInfo.getDefaultAccessType() );
probably should be
return TypeUtils.getElementKindForAccessType( accessTypeInfo.getAccessType() );
which was good because line 196 would lead the code to look for attributes (not methods) to compare to the property-name.
If the element was not the same one as was expected, the loop would skip that element. This seemed strange to me.
if ( expectedElementKind.equals( elem.getKind() ) ) {
continue;
}
As I said, attached is my solution in which, I hope, will confirm to the JPA-specification ;-).
Regards,
Martijn Blankestijn
--
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, 9 months