I have a node tree with a composite key, comprising a single table with a foreign (composite) key pointing to itself.
I figured out how to map a Set of all the children of a node, but finding the Set of all the siblings of a node has me beat. I get the following PersistenceException:
<handlePersistException> Database persistence problem - exception PersistenceException
<logStackTrace> throwable.getMessage (): referencedColumnNames(parentName, parentDupleNr) of model.genre.GenreView.siblings referencing model.genre.GenreLink not mapped to a single property
<logStackTrace> <<<stack trace begins>>>
<logStackTrace> at <org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference> [BinderHelper.java:204]
<logStackTrace> from <org.hibernate.cfg.ToOneFkSecondPass.doSecondPass> [ToOneFkSecondPass.java:114]
<logStackTrace> from <org.hibernate.cfg.Configuration.processEndOfQueue> [Configuration.java:1,550]
<logStackTrace> from <org.hibernate.cfg.Configuration.processFkSecondPassInOrder> [Configuration.java:1,473]
<logStackTrace> from <org.hibernate.cfg.Configuration.secondPassCompile> [Configuration.java:1,389]
<logStackTrace> from <org.hibernate.cfg.Configuration.buildMappings> [Configuration.java:1,345]
<logStackTrace> from <org.hibernate.ejb.Ejb3Configuration.buildMappings> [Ejb3Configuration.java:1,477]
<logStackTrace> from <org.hibernate.ejb.EventListenerConfigurator.configure> [EventListenerConfigurator.java:193]
<logStackTrace> from <org.hibernate.ejb.Ejb3Configuration.configure> [Ejb3Configuration.java:1,096]
<logStackTrace> from <org.hibernate.ejb.Ejb3Configuration.configure> [Ejb3Configuration.java:278]
<logStackTrace> from <org.hibernate.ejb.Ejb3Configuration.configure> [Ejb3Configuration.java:362]
<logStackTrace> from <org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory> [HibernatePersistence.java:56]
<logStackTrace> from <javax.persistence.Persistence.createEntityManagerFactory> [Persistence.java:48]
<logStackTrace> from <javax.persistence.Persistence.createEntityManagerFactory> [Persistence.java:32]
<logStackTrace> from <server.persist.Transaction.begin> [Transaction.java:49]
<logStackTrace> from <server.persist.GenreDao.getView> [GenreDao.java:44]
<logStackTrace> from <model.genre.Genre.getView> [Genre.java:37]
<logStackTrace> from <control.action.GetGenreView.execute> [GetGenreView.java:34]
<logStackTrace> from <control.servlet.ViewServlet.doRequest> [ViewServlet.java:235]
<logStackTrace> from <control.servlet.ViewServlet.doGet> [ViewServlet.java:203]
<logStackTrace> from <javax.servlet.http.HttpServlet.service> [HttpServlet.java:621]
<logStackTrace> from <javax.servlet.http.HttpServlet.service> [HttpServlet.java:722]
<logStackTrace> from <org.apache.catalina.core.ApplicationFilterChain.internalDoFilter> [ApplicationFilterChain.java:306]
<logStackTrace> from <org.apache.catalina.core.ApplicationFilterChain.doFilter> [ApplicationFilterChain.java:210]
<logStackTrace> from <org.apache.catalina.core.StandardWrapperValve.invoke> [StandardWrapperValve.java:240]
<logStackTrace> from <org.apache.catalina.core.StandardContextValve.invoke> [StandardContextValve.java:161]
<logStackTrace> from <org.apache.catalina.core.StandardHostValve.invoke> [StandardHostValve.java:164]
<logStackTrace> from <org.apache.catalina.valves.ErrorReportValve.invoke> [ErrorReportValve.java:100]
<logStackTrace> from <org.apache.catalina.valves.AccessLogValve.invoke> [AccessLogValve.java:541]
<logStackTrace> from <org.apache.catalina.core.StandardEngineValve.invoke> [StandardEngineValve.java:118]
<logStackTrace> from <org.apache.catalina.connector.CoyoteAdapter.service> [CoyoteAdapter.java:383]
<logStackTrace> from <org.apache.coyote.http11.Http11Processor.process> [Http11Processor.java:243]
<logStackTrace> from <org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process> [Http11Protocol.java:188]
<logStackTrace> from <org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process> [Http11Protocol.java:166]
<logStackTrace> from <org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run> [JIoEndpoint.java:288]
<logStackTrace> from <java.util.concurrent.ThreadPoolExecutor$Worker.runTask> [unknown]
<logStackTrace> from <java.util.concurrent.ThreadPoolExecutor$Worker.run> [unknown]
<logStackTrace> from <java.lang.Thread.run> [unknown]
<logStackTrace> <<<stack trace ends>>>
The "not mapped to a single property" message is puzzling me - it's a composite key!
The (embeddable) composite key Class:
Code:
package model.genre;
import java.io.Serializable;
import javax.persistence.Embeddable;
import javax.persistence.Basic;
@Embeddable
public class GenreKey implements Serializable
{
private static final long serialVersionUID = 1L;
@Basic
private String name = "";
@Basic
private short dupleNr = 0;
public void setName (String name)
{
this.name = name;
}
public String getName ()
{
return this.name;
}
public void setDupleNr (short dupleNr)
{
this.dupleNr = dupleNr;
}
public short getDupleNr ()
{
return this.dupleNr;
}
public boolean equals (Object compareObject)
{
...
}
public int hashCode ()
{
...
}
}
The tree node Class (simplified a bit):
Code:
package model.genre;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.EmbeddedId;
import javax.persistence.Embedded;
import javax.persistence.Basic;
import javax.persistence.AttributeOverrides;
import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.FetchType;
import javax.persistence.OrderBy;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import java.util.Set;
import java.util.TreeSet;
@Entity @Table (schema = "FanDb", name = "Genre")
public class GenreView
{
@EmbeddedId
private GenreKey key = new GenreKey ();
@Embedded
@AttributeOverrides ({@AttributeOverride (name = "name", column = @Column (name = "parentName")),
@AttributeOverride (name = "dupleNr", column = @Column (name = "parentDupleNr"))})
private GenreKey parentKey = new GenreKey ();
@Basic
private String info = "";
@ManyToOne (targetEntity = GenreLink.class)
@OrderBy ("key.name, key.dupleNr")
@JoinColumns ({@JoinColumn (name = "parentName", referencedColumnName = "parentName"),
@JoinColumn (name = "parentDupleNr", referencedColumnName = "parentDupleNr")})
private Set<GenreLink> siblings = new TreeSet<GenreLink> ();
@OneToMany (fetch = FetchType.EAGER)
@OrderBy ("key.name, key.dupleNr")
@JoinColumns ({@JoinColumn (name = "parentName", referencedColumnName = "name"),
@JoinColumn (name = "parentDupleNr", referencedColumnName = "dupleNr")})
private Set<GenreLink> children = new TreeSet<GenreLink> ();
public GenreKey getKey ()
{
return this.key;
}
public GenreKey getParentKey ()
{
return this.parentKey;
}
public Wiki getInfo ()
{
return this.info;
}
public Set<GenreLink> getSiblings ()
{
return this.siblings;
}
public Set<GenreLink> getChildren ()
{
return this.children;
}
}
The tree link Class:
Code:
package model.genre;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.EmbeddedId;
import javax.persistence.Embedded;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import java.lang.Comparable;
@Entity @Table (schema = "FanDb", name = "Genre")
public class GenreLink implements Comparable<GenreLink>
{
@EmbeddedId
private GenreKey key = new GenreKey ();
@Embedded
@AttributeOverrides ({@AttributeOverride (name = "name", column = @Column (name = "parentName")),
@AttributeOverride (name = "dupleNr", column = @Column (name = "parentDupleNr"))})
private GenreKey parentKey = new GenreKey ();
public GenreKey getKey ()
{
return this.key;
}
public GenreKey getParentKey ()
{
return this.parentKey;
}
public int compareTo (GenreLink compareLink)
{
...
}
}
And the failing piece of code:
Code:
EntityManagerFactory factory = Persistence.createEntityManagerFactory ("server.persist.Transaction"); // fails here!
EntityManager manager = this.factory.createEntityManager ();
EntityTransaction transaction = this.manager.getTransaction ();
transaction.begin ();
What is the mysterious error message "not mapped to a single property" trying to tell me? Is the mapping correct?
Thanks, MC
[Tomcat 7.0.8 / Annotations 3.4.0 / Entity Manager 3.4.0 / Core 3.6.1 / MySQL 5.5.9 / Connector/J 5.1.15]