openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpalache <ravi.palache...@oracle.com>
Subject Re: UniqueConstraint in a MappedSuperclass not working
Date Tue, 14 Apr 2009 22:02:37 GMT

Hi ,

May be you are already aware, Workaround would be to use "unique constraint" in sub class.
So in your example, 
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"ATTR_NAME", "OWNER"})})
will go to OrgAttribute and look like:
@Table(name = "ORG_ATTR",uniqueConstraints={@UniqueConstraint(columnNames={"ATTR_NAME", "OWNER"})})

I think it would be nice if the uniqueconstraint can be defined in the super class itself.

As far as it is bug or not, may be some openJPA expert can help answer that.

According to my view, it is more of any enhancement request rather than a bug.
My conclusion is based on following, Table annotation is for an entity class and mappedSuperclass
is a non-entity class.

Regards,
Ravi.


Hello, I think this is a bug:

I am getting 
Caused by: <openjpa-1.2.1-r752877:753278 nonfatal user error> org.apache.openjpa.persistence.ArgumentException:
The column "ATTR_NAME" in a unique constraint in "foo.bar.Attribute" on table "null" can not
be found in the list of available columns "[]".
	at org.apache.openjpa.jdbc.meta.ClassMappingInfo.getUniques(ClassMappingInfo.java:432)
	at org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.java:857)
	at org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1631)
	at org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataRepository.java:717)
	at org.apache.openjpa.meta.MetaDataRepository.resolveMapping(MetaDataRepository.java:677)
	at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:555)
	at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:308)
	at org.apache.openjpa.meta.MetaDataRepository.resolveMeta(MetaDataRepository.java:581)
	at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:541)
	at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:308)
	at org.apache.openjpa.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:285)
	at org.apache.openjpa.jdbc.meta.MappingTool.getMapping(MappingTool.java:676)
	at org.apache.openjpa.jdbc.meta.MappingTool.buildSchema(MappingTool.java:748)
	at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:646)
	at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:153)
	at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:119)
	at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:189)
	at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:145)

I have a class
@MappedSuperclass
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"ATTR_NAME", "OWNER"})})
public abstract class Attribute<T> {
	@Id
	private String id;

	@Column(name="ATTR_NAME")
	private String name;
	
	@Column(name="ATTR_VALUE")
	private String value;

	public abstract T getOwner();
	public abstract void setOwner(T owner);

and it is extended by
@Entity
@Table(name = "ORG_ATTR")
public class OrgAttribute extends Attribute<Org> {
	@ManyToOne
	@JoinColumn(name = "OWNER")
	private Org owner;

	@Override
	public Org getOwner() {
		return owner;
	}

	@Override
	public void setOwner(Org owner) {
		this.owner = owner;
	}
}

This mapping is working in both Eclipselink and Hibernate


-- 
View this message in context: http://n2.nabble.com/UniqueConstraint-in-a-MappedSuperclass-not-working-tp2633410p2635628.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message