HHH-10217 - ModelBinder fails to bind version property when generated="always"
This commit is contained in:
parent
8bcf66631d
commit
56fae44589
|
@ -2476,46 +2476,23 @@ public class ModelBinder {
|
||||||
|
|
||||||
// generated properties can *never* be insertable...
|
// generated properties can *never* be insertable...
|
||||||
if ( property.isInsertable() ) {
|
if ( property.isInsertable() ) {
|
||||||
if ( singularAttributeSource.isInsertable() == null ) {
|
log.debugf(
|
||||||
// insertable simply because that is the user did not specify
|
"Property [%s] specified %s generation, setting insertable to false : %s",
|
||||||
// anything; just override it
|
propertySource.getName(),
|
||||||
property.setInsertable( false );
|
generationTiming.name(),
|
||||||
}
|
mappingDocument.getOrigin()
|
||||||
else {
|
);
|
||||||
// the user specifically supplied insert="true",
|
property.setInsertable( false );
|
||||||
// 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()
|
|
||||||
),
|
|
||||||
mappingDocument.getOrigin()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// properties generated on update can never be updatable...
|
// properties generated on update can never be updatable...
|
||||||
if ( property.isUpdateable() && generationTiming == GenerationTiming.ALWAYS ) {
|
if ( property.isUpdateable() && generationTiming == GenerationTiming.ALWAYS ) {
|
||||||
if ( singularAttributeSource.isUpdatable() == null ) {
|
log.debugf(
|
||||||
// updatable only because the user did not specify
|
"Property [%s] specified ALWAYS generation, setting updateable to false : %s",
|
||||||
// anything; just override it
|
propertySource.getName(),
|
||||||
property.setUpdateable( false );
|
mappingDocument.getOrigin()
|
||||||
}
|
);
|
||||||
else {
|
property.setUpdateable( false );
|
||||||
// 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()
|
|
||||||
),
|
|
||||||
mappingDocument.getOrigin()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ import org.hibernate.tool.schema.spi.SchemaManagementTool;
|
||||||
import org.hibernate.testing.FailureExpected;
|
import org.hibernate.testing.FailureExpected;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
import org.hibernate.test.hbm.JournalingSchemaToolingTarget;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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 {
|
public class Person {
|
||||||
private long id;
|
private long id;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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
|
* @author Steve Ebersole
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,7 +9,7 @@
|
||||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
"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">
|
<class name="PersonGroup">
|
||||||
<id name="id" type="long">
|
<id name="id" type="long">
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
"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">
|
<class name="Person">
|
||||||
<id name="id" type="long">
|
<id name="id" type="long">
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
"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">
|
<class name="Person">
|
||||||
<id name="id" type="long">
|
<id name="id" type="long">
|
||||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue