[Hibernate-JIRA] Created: (HHH-5837) Hibernate should no log exceptions on its own - just throw them and let the service layer decide
by Grzegorz Borkowski (JIRA)
Hibernate should no log exceptions on its own - just throw them and let the service layer decide
------------------------------------------------------------------------------------------------
Key: HHH-5837
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5837
Project: Hibernate Core
Issue Type: Improvement
Components: core
Affects Versions: 3.5.3
Reporter: Grzegorz Borkowski
Example:
In an invoicing application there is a constraint on an invoice table, ensuring that invoice numbers must be unique. This column is not a primary key, for some reason. So, there is a unique constraint at database level on this column. When the user creates duplicate record, I expect that Hibernate just throw the appropriate exception. and the service layer will process correctly this exception and tell the user "pls choose a different number".
But currently Hibernate also logs several (!) error lines in log file, when it happens, like this:
o.h.e.d.AbstractFlushingEventListener - Could not synchronize database state with session org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
o.h.util.JDBCExceptionReporter - Duplicate entry '...' for key '...'
o.h.util.JDBCExceptionReporter - SQL Error: 1062, SQLState: 23000
The problem is that in our setup any error logged, causes new e-mail being sent to system admin - because the error means something went wrong and admin should take care of this. But in this case its nothing wrong with the system - the application is able to handle such errors, so no error should be logged. Generally it's considered to be the good practice that low-level layers and libraries (like ORM) shouldn't take business-level dicisions. Deciding on whether to log an error message to log file or not is a business-level decision, so let the appropriate leyer decide - it's not Hibernate responsibility. Just throw the appropriate exception.
Exactly the same situation happens when deadlock is detected. We have a kind of intercepor in front of service layer, that automatically restarts transaction when deadlock is detected. So again it's this interceptor responsibilty to either restart the transaction automatically, or log the erro (e.g. after some number of repeates). But the same problem here: Hibernate takes the responsibilty on itself and print several (again several - very bas practice!) log statements:
o.h.e.d.AbstractFlushingEventListener - Could not synchronize database state with session org.hibernate.exception.LockAcquisitionException: Could not execute JDBC batch update
o.h.util.JDBCExceptionReporter - Deadlock found when trying to get lock; try restarting transaction
o.h.util.JDBCExceptionReporter - SQL Error: 1213, SQLState: 40001
(BTW it would be much better if some special exception was thrown in such a case, so that we can take decision based on exception class - now we have to parse the message string, searching for 'try restarting transaction' text - very fragile).
Obviously, we can turn the logging off for Hibernate loggers, but it's not perfect solution too (e.g. then we will miss any warnings generated potentially by those loggers).
--
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
13 years, 12 months
[Hibernate-JIRA] Created: (HHH-5495) Unknown mappedBy using @Id @OneToOne
by Alfio (JIRA)
Unknown mappedBy using @Id @OneToOne
------------------------------------
Key: HHH-5495
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5495
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.6.0.Beta3, 3.5.0-Final
Environment: Hibernate 3.5 and 3.6.0-Beta3
Glassfish v3.0.1
Reporter: Alfio
Attachments: test.zip
This example should work according to JSR 317, Section 2.4.1.3, Example 4 Case(a):
@Entity
public class Person {
@Id
private String ssn;
@Column( nullable = false )
private String name;
@Column( nullable = false )
private String surname;
@OneToOne( mappedBy = "person" )
private PersonDetail personDetail;
... getters and setters ...
}
@Entity
public class PersonDetail {
@Id
@OneToOne
private Person person;
@Column( nullable = true )
private int age;
@Column( nullable = true )
private String city;
... getters and setters ...
}
----
During deploy the following error is shown:
Exception while preparing the app org.hibernate.AnnotationException: Unknown mappedBy in: test.Person.personDetail, referenced property unknown: test.PersonDetail.person
at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:159)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1754)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1461)
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:677)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:181)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:96)
at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:121)
at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:644)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:296)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365)
at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)
---
It works well if I use MapsId (following example 4 case b in JSR 317)
@Entity
public class PersonDetail {
@Id
private String ssnPK;
@MapsId
@OneToOne
private Person person;
...
--
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
13 years, 12 months
[Hibernate-JIRA] Created: (HHH-5826) org.hibernate.util.SerializationHelper#resolveClass never tries loader3
by Stian Thorgersen (JIRA)
org.hibernate.util.SerializationHelper#resolveClass never tries loader3
-----------------------------------------------------------------------
Key: HHH-5826
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5826
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.6.0
Reporter: Stian Thorgersen
In my application SerializationHelper throws a ClassNotFoundException when I try to retrieve a entity with a blob type from the database. This is caused by what looks like a copy/paste mistake in {{org.hibernate.util.SerializationHelper#resolveClass}}.
In the below code (extract from org.hibernate.util.SerializationHelper#resolveClass), {{loader2}} is tried twice and {{loader3}} is never tried.
{code}
if ( different( loader1, loader2 ) ) {
try {
return Class.forName( className, false, loader2 );
}
catch ( ClassNotFoundException e ) {
log.trace( "Unable to locate class using given classloader" );
}
}
if ( different( loader1, loader3 ) && different( loader2, loader3 ) ) {
try {
return Class.forName( className, false, loader2 );
}
catch ( ClassNotFoundException e ) {
log.trace( "Unable to locate class using given classloader" );
}
}
{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
13 years, 12 months