HHH-10217 - ModelBinder fails to bind version property when generated="always"

This commit is contained in:
Steve Ebersole 2015-10-26 17:00:06 -05:00
parent 8bcf66631d
commit 56fae44589
11 changed files with 110 additions and 44 deletions

View File

@ -2476,46 +2476,23 @@ public class ModelBinder {
// generated properties can *never* be insertable...
if ( property.isInsertable() ) {
if ( singularAttributeSource.isInsertable() == null ) {
// insertable simply because that is the user did not specify
// anything; just override it
property.setInsertable( false );
}
else {
// the user specifically supplied insert="true",
// which constitutes an illegal combo
throw new MappingException(
String.format(
Locale.ENGLISH,
"Cannot specify both insert=\"true\" and generated=\"%s\" for property %s",
generationTiming.name().toLowerCase(Locale.ROOT),
propertySource.getName()
),
log.debugf(
"Property [%s] specified %s generation, setting insertable to false : %s",
propertySource.getName(),
generationTiming.name(),
mappingDocument.getOrigin()
);
}
property.setInsertable( false );
}
// properties generated on update can never be updatable...
if ( property.isUpdateable() && generationTiming == GenerationTiming.ALWAYS ) {
if ( singularAttributeSource.isUpdatable() == null ) {
// updatable only because the user did not specify
// anything; just override it
property.setUpdateable( false );
}
else {
// the user specifically supplied update="true",
// which constitutes an illegal combo
throw new MappingException(
String.format(
Locale.ENGLISH,
"Cannot specify both update=\"true\" and generated=\"%s\" for property %s",
generationTiming.name().toLowerCase(Locale.ROOT),
propertySource.getName()
),
log.debugf(
"Property [%s] specified ALWAYS generation, setting updateable to false : %s",
propertySource.getName(),
mappingDocument.getOrigin()
);
}
property.setUpdateable( false );
}
}
}

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.hbm;
package org.hibernate.test.hbm.index;
import java.util.Collections;
@ -18,7 +18,6 @@ import org.hibernate.tool.schema.spi.SchemaManagementTool;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.test.hbm.JournalingSchemaToolingTarget;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.hbm;
package org.hibernate.test.hbm.index;
import java.util.ArrayList;
import java.util.List;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.hbm;
package org.hibernate.test.hbm.index;
public class Person {
private long id;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.hbm;
package org.hibernate.test.hbm.index;
/**
* @author Steve Ebersole

View File

@ -0,0 +1,25 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.hbm.version;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
/**
* @author Steve Ebersole
*/
public class GeneratedVersionBindingTest extends BaseUnitTestCase {
@Test
public void testIt() {
final Metadata metadata = new MetadataSources()
.addResource("org/hibernate/test/hbm/version/Mappings.hbm.xml")
.buildMetadata();
}
}

View File

@ -0,0 +1,40 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.hbm.version;
/**
* @author Steve Ebersole
*/
public class Order {
private Integer id;
private String referenceCode;
private byte[] rv;
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getReferenceCode() {
return this.referenceCode;
}
public void setReferenceCode(String referenceCode) {
this.referenceCode = referenceCode;
}
public byte[] getRv() {
return this.rv;
}
public void setRv(byte[] rv) {
this.rv = rv;
}
}

View File

@ -9,7 +9,7 @@
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.hbm">
<hibernate-mapping package="org.hibernate.test.hbm.index">
<class name="PersonGroup">
<id name="id" type="long">

View File

@ -9,7 +9,7 @@
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.hbm">
<hibernate-mapping package="org.hibernate.test.hbm.index">
<class name="Person">
<id name="id" type="long">

View File

@ -9,7 +9,7 @@
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.hbm">
<hibernate-mapping package="org.hibernate.test.hbm.index">
<class name="Person">
<id name="id" type="long">

View File

@ -0,0 +1,25 @@
<?xml version="1.0"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.hibernate.test.hbm.version.Order">
<id name="id">
<generator class="increment"/>
</id>
<natural-id>
<property name="referenceCode"/>
</natural-id>
<version name="rv" column="rv" type="binaryUserType" insert="false" generated="always" />
</class>
</hibernate-mapping>