OPENJPA-1612: Check for having a relationship to a type that is mapped to a blob field.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@942871 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Richard G. Curtis 2010-05-10 19:46:21 +00:00
parent cb77af09f2
commit 2765b756bc
6 changed files with 93 additions and 5 deletions

View File

@ -883,6 +883,13 @@ public class MappingRepository extends MetaDataRepository {
// default to blob
if (installHandlers) {
int type = field.getAssociationType();
// Having a ONE_TO_ONE, ONE_TO_MANY, MANY_TO_ONE, or MANY_TO_MANY relationship
// type as a blob is incorrect
if (type >= FieldMetaData.ONE_TO_ONE && type <= FieldMetaData.MANY_TO_MANY) {
throw new UserException(_loc.get("invalid-mapping", field));
}
if (getLog().isWarnEnabled())
getLog().warn(_loc.get("no-field-strategy", field));
field.setSerialized(true);

View File

@ -417,4 +417,5 @@ unique-no-table: A unique constraint on table "{0}" can not be added to \
table "{2}" nor any of its secondary table(s) "{3}".
bad-version-column-table: One of the version column "{0}" has been associated \
with table "{1}", but no primary or secondary table of such name exists.
version-type-unsupported: Version field "{0}" of {1} is not supported.
version-type-unsupported: Version field "{0}" of {1} is not supported.
invalid-mapping: The field "{0}" is an invalid type. Relationship fields must be a valid Entity type.

View File

@ -34,7 +34,7 @@ public class ConstantJoinPC4
@OneToOne(cascade={CascadeType.PERSIST, CascadeType.REMOVE})
private ConstantJoinPC5 oneToOne1;
@ManyToMany
private Set manyToMany = new HashSet ();
public ConstantJoinPC4()

View File

@ -18,12 +18,14 @@
*/
package org.apache.openjpa.persistence.kernel.common.apps;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.OneToOne;
@Entity
@ -34,13 +36,12 @@ public class BlobTest {
private int id;
@Column(name = "blobtab")
@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
private Object blob;
private byte[] blob;
public BlobTest() {
}
public void setBlob(Object blob) {
public void setBlob(byte[] blob) {
this.blob = blob;
}

View File

@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.openjpa.persistence.meta;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
@Entity
public class InvalidMappingFieldEntity {
@Id
int id;
@ManyToOne
Object o;
@OneToOne
InvalidMappingFieldEntity other;
}

View File

@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.openjpa.persistence.meta;
import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
import org.apache.openjpa.util.UserException;
public class TestMappingRepository extends SingleEMFTestCase {
@Override
protected void setUp(Object... props) {
super.setUp(InvalidMappingFieldEntity.class, "openjpa.jdbc.SynchronizeMappings", "false");
}
public void test() {
try {
OpenJPAEntityManagerSPI em = emf.createEntityManager();
emf.getConfiguration().getMetaDataRepositoryInstance().getMetaData(InvalidMappingFieldEntity.class, null,
true);
fail("Shouldn't be able to create an em with this Entity type.");
} catch (UserException e) {
// expected
}
}
}