openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpalache <>
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.


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 "" on table "null" can not
be found in the list of available columns "[]".
	at org.apache.openjpa.jdbc.meta.ClassMappingInfo.getUniques(
	at org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(
	at org.apache.openjpa.meta.ClassMetaData.resolve(
	at org.apache.openjpa.meta.MetaDataRepository.processBuffer(
	at org.apache.openjpa.meta.MetaDataRepository.resolveMapping(
	at org.apache.openjpa.meta.MetaDataRepository.resolve(
	at org.apache.openjpa.meta.MetaDataRepository.getMetaData(
	at org.apache.openjpa.meta.MetaDataRepository.resolveMeta(
	at org.apache.openjpa.meta.MetaDataRepository.resolve(
	at org.apache.openjpa.meta.MetaDataRepository.getMetaData(
	at org.apache.openjpa.jdbc.meta.MappingRepository.getMapping(
	at org.apache.openjpa.jdbc.meta.MappingTool.getMapping(
	at org.apache.openjpa.jdbc.meta.MappingTool.buildSchema(
	at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(
	at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(
	at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(
	at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(
	at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(

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

	private String name;
	private String value;

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

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

	public Org getOwner() {
		return owner;

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

This mapping is working in both Eclipselink and Hibernate

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message