[Hibernate-JIRA] Created: (HHH-6880) Implementations of org.hibernate.type.Type contain references to non-serializable entities
by Mindaugas Žakšauskas (JIRA)
Implementations of org.hibernate.type.Type contain references to non-serializable entities
------------------------------------------------------------------------------------------
Key: HHH-6880
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6880
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.7
Environment: Seen this on MySQL but I believe this is environment-agnostic
Reporter: Mindaugas Žakšauskas
Priority: Critical
This is a spin-off from
- https://forum.hibernate.org/viewtopic.php?f=1&t=1013687&sid=e62b8ea711e49...
- http://stackoverflow.com/q/8404559/7345
org.hibernate.cache.CacheKey is an object which is used for L2 cache notifications - e.g. to flush a cache on a different cluster node when a certain object has been updated.
The problem comes from org.hibernate.cache.CacheKey carrying the type which (sometimes) happens to have a reference to objects like org.hibernate.impl.SessionFactoryImpl.
This problem is actually not just theoretic but also causes real pain. First, it takes much longer to broadcast cache flush events. Secondly, I get this exception during deserialization of such a CacheKey:
java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:768)
at org.hibernate.impl.SessionFactoryObjectFactory.getNamedInstance(SessionFactoryObjectFactory.java:159)
at org.hibernate.impl.SessionFactoryImpl.readResolve(SessionFactoryImpl.java:753)
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 java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1061)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1762)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readUnshared(ObjectInputStream.java:441)
at my.class.deserializeKey(EhcacheUtils.java:35)
I have done a quick scan through all the types, and found these problems related to their serializability:
1) org.hibernate.type.CollectionType, org.hibernate.type.ComponentType and subclasses of both - they use attribute "typeScope" (of type TypeFactory.TypeScope) which is assigned in the constructor and kept in the but seems to be never used. The typeScope in turn has a reference to the SessionImpl. Can it simply be removed?
2) org.hibernate.type.EntityType (and its subclasses) stores typeScope and only uses it in the getter, so I guess it should be safe to remove it, too.
3) org.hibernate.type.SortedSetType and org.hibernate.type.SortedMapType keeps a reference to the comparator, but does not enforce its serializability. It should at least throw a runtime exception in org.hibernate.mapping.Collection::getComparator if the comparator is not serializable.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 4 months
[Hibernate-JIRA] Created: (HV-547) Make Hibernate Validator build not fail
by Emmanuel Bernard (JIRA)
Make Hibernate Validator build not fail
---------------------------------------
Key: HV-547
URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-547
Project: Hibernate Validator
Issue Type: Improvement
Components: build
Reporter: Emmanuel Bernard
When running mvn clean install, I always get failures on the manual build.
{code}
[INFO] Hibernate Validator Aggregator .................... SUCCESS [1.319s]
[INFO] Hibernate Validator ............................... SUCCESS [27.278s]
[INFO] Hibernate Validator TCK Runner .................... SUCCESS [19.637s]
[INFO] Hibernate Validator Integration Tests ............. SUCCESS [26.355s]
[INFO] Hibernate Validator Annotation Processor .......... SUCCESS [3.330s]
[INFO] Hibernate Validator Quickstart .................... SUCCESS [12.296s]
[INFO] Hibernate Validator Manual ........................ FAILURE [19.885s]
[INFO] Hibernate Validator Distribution .................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:55.078s
[INFO] Finished at: Fri Dec 23 14:36:25 CET 2011
[INFO] Final Memory: 45M/108M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jboss.maven.plugins:maven-jdocbook-plugin:2.3.5:translate (default) on project hibernate-validator-documentation: Unexpected problem: unable to execute po2xml : Cannot run program "po2xml": error=2, No such file or directory -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :hibernate-validator-documentation
{code}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 4 months
[Hibernate-JIRA] Created: (HV-512) Composed constraints lose the payload information of the constraints they are composed of
by Geoff The (JIRA)
Composed constraints lose the payload information of the constraints they are composed of
-----------------------------------------------------------------------------------------
Key: HV-512
URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-512
Project: Hibernate Validator
Issue Type: Bug
Components: validators
Affects Versions: 4.2.0.Final
Reporter: Geoff The
If a payload is set for child constraints in a composed constraint, their payload values will be ignored.
HV-183 dealt with the propagation of the parent's payload down to the children constraints, but it also overwrites any payload the children may have had.
I would suggest that if the children have any explicit payloads defined, they should be integrated into the parents and not blown away.
{code}
import org.junit.*;
import javax.validation.*;
import javax.validation.constraints.NotNull;
import java.lang.annotation.*;
import java.util.*;
import static org.junit.Assert.*;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
public class TestPayload {
public static class Warning implements Payload {}
public static class Error implements Payload {}
@Documented
@Constraint(validatedBy = NameMustBeGeoffValidator.class)
@Target({ TYPE, METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
public @interface NameMustBeGeoff {
String message() default "{NameMustBeGeoff.message}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
public static class NameMustBeGeoffValidator implements ConstraintValidator<NameMustBeGeoff, Customer> {
@Override
public void initialize(NameMustBeGeoff constraintAnnotation) {}
@Override
public boolean isValid(Customer value, ConstraintValidatorContext context) {
return ((value.getName() == null) || (value.getName().equals("Geoff")));
}
}
@NameMustBeGeoff(payload = Error.class)
@Documented
@Constraint(validatedBy = ValidCustomerValidator.class)
@Target({ TYPE, METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
public @interface ValidCustomer {
String message() default "{ValidCustomer.message}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
public static class ValidCustomerValidator implements ConstraintValidator<ValidCustomer, Customer> {
@Override
public void initialize(ValidCustomer constraintAnnotation) {}
@Override
public boolean isValid(Customer value, ConstraintValidatorContext context) { return true; }
}
@ValidCustomer
public class Customer {
private String name;
public Customer(String name) { this.name = name; }
@NotNull(payload = Warning.class)
public String getName() { return this.name; }
}
/**
* Customer's name is null, it should trigger the @NotNull with a Warning payload
*/
@Test
public void test() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Customer customer = new Customer(null);
Set<ConstraintViolation<Customer>> violations = validator.validate(customer);
assertEquals(1, violations.size());
ConstraintViolation<Customer> violation = violations.iterator().next();
assertEquals("may not be null", violation.getMessage());
assertEquals("javax.validation.constraints.NotNull", violation.getConstraintDescriptor().getAnnotation().annotationType().getName());
assertEquals(1, violation.getConstraintDescriptor().getPayload().size());
assertEquals(Warning.class, violation.getConstraintDescriptor().getPayload().iterator().next());
}
/**
* Customer's name is not Geoff and should trigger the NameMustBeGeoff constraint, but the Error payload is lost
*/
@Test
public void testPayloadInComposedConstraints() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Customer customer = new Customer("Bob");
Set<ConstraintViolation<Customer>> violations = validator.validate(customer);
assertEquals(1, violations.size());
ConstraintViolation<Customer> violation = violations.iterator().next();
assertEquals("{NameMustBeGeoff.message}", violation.getMessage());
assertEquals("org.geofft.TestPayload$NameMustBeGeoff", violation.getConstraintDescriptor().getAnnotation().annotationType().getName());
assertEquals(0, violation.getConstraintDescriptor().getPayload().size()); // Not what I expected
/*
What I think should happen:
assertEquals(1, violation.getConstraintDescriptor().getPayload().size());
assertEquals(Customer.Error.class, violation.getConstraintDescriptor().getPayload().iterator().next());
*/
}
}
{code}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 4 months
[Hibernate-JIRA] Created: (HHH-6934) optional=false add an unexpected unique constraint
by Lorber Sebastien (JIRA)
optional=false add an unexpected unique constraint
--------------------------------------------------
Key: HHH-6934
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6934
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.4
Environment: Oracle 10g, Hibernate 3.6.4, Hbm2ddl, H2...
Reporter: Lorber Sebastien
Priority: Minor
I have a very simple OneToOne relationship:
@OneToOne(optional = false,orphanRemoval = false)
@JoinColumn (name="leadform_id",unique=false)
public Leadform getLeadform() {
return leadform;
}
When using optional = false
I get in my hbm2ddl schema: unique (leadform_id)
When using optional = true, i don't have that unique constraint.
Documentation says:
"If set to false then a non-null relationship must always exist."
And in my case it does, but the documentation doesn't say this optional attribute has any effect on the unique constraint.
Actually i think everybody expect that constraint to be handled by the JoinColumn unique=false attribute, or at least to find the information in the documentation.
It affects hbm2ddl when using the maven hibernate3:hbm2ddl goal but also when hibernate creates the test tables in H2
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 4 months
[Hibernate-JIRA] Created: (HHH-6932) Quick Start basic tutorial test fails
by Peter Lynch (JIRA)
Quick Start basic tutorial test fails
-------------------------------------
Key: HHH-6932
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6932
Project: Hibernate Core
Issue Type: Bug
Components: testsuite
Affects Versions: 4.0.0.Final
Reporter: Peter Lynch
The basic tutorial included with the version 4.0.0.Final download includes a JUnit test which fails when executed.
Steps to reproduce:
1. Download and extract version 4.0.0.Final from http://sourceforge.net/projects/hibernate/files/hibernate4/4.0.0.Final/
2. Unzip \documentation\quickstart\en-US\html\files\hibernate-tutorials.zip
3. Navigate to the extract directory and open command prompt at the \basic subdirectory
4. Type mvn clean test
Expected behaviour:
Test runs successfully
Actual behaviour:
"resource: org/hibernate/tutorial/hbm/Event.hbm.xml not found". Stacktrace:
E:\java\hibernate-tutorial\basic>mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Hibernate hbm.xml Tutorial 4.0.0.Final
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ hibernate-tutorial-hbm ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\java\hibernate-tutorial\basic\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ hibernate-tutorial-hbm ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ hibernate-tutorial-hbm ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\java\hibernate-tutorial\basic\src\main\java
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ hibernate-tutorial-hbm ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 2 source files to E:\java\hibernate-tutorial\basic\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ hibernate-tutorial-hbm ---
[INFO] Surefire report directory: E:\java\hibernate-tutorial\basic\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.hibernate.tutorial.hbm.NativeApiIllustrationTest
3/01/2012 10:37:55 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
3/01/2012 10:37:55 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.0.0.Final}
3/01/2012 10:37:55 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
3/01/2012 10:37:55 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
3/01/2012 10:37:55 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
3/01/2012 10:37:55 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
3/01/2012 10:37:55 AM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: org/hibernate/tutorial/hbm/Event.hbm.xml
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.171 sec <<< FAILURE!
Results :
Tests in error:
testBasicUsage(org.hibernate.tutorial.hbm.NativeApiIllustrationTest): resource: org/hibernate/tutorial/hbm/Event.hbm.xml not found
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.344s
[INFO] Finished at: Tue Jan 03 10:37:55 NZDT 2012
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.7.2:test (default-test) on project hibernate-tutoria
l-hbm: There are test failures.
[ERROR]
[ERROR] Please refer to E:\java\hibernate-tutorial\basic\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Suggested fix:
Move the Event.hbm.xml from \basic\src\test\java\org\hibernate\tutorial\hbm\ to \basic\src\test\resources\org\hibernate\tutorial\hbm\
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 4 months