Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » mapping problem: entity as join table
mapping problem: entity as join table [message #386050] Thu, 19 March 2009 20:56 Go to next message
andiqo  is currently offline andiqo Friend
Messages: 32
Registered: July 2009
Member
Dear all,

I have a problem with my mapping... Help appreciated.

** In Java:

@Entity
public class Node implements ICopyable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private long id;

@ManyToMany(mappedBy = "to", fetch = FetchType.LAZY, cascade =
CascadeType.ALL)
// No orphanRemoval here => see preRemove method
private Set<Edge> inputs = new HashSet<Edge>();

@ManyToMany(mappedBy = "from", fetch = FetchType.LAZY, cascade =
CascadeType.ALL)
// No orphanRemoval here => see preRemove method
private Set<Edge> outputs = new HashSet<Edge>();
}

@Entity
public class Edge {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private long id;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "FROM_ID", nullable = false, updatable = false)
private Node from;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "TO_ID", nullable = false, updatable = false)
private Node to;
}

** In SQL (PostgresQL)

CREATE TABLE EDGE (ID BIGSERIAL NOT NULL, TO_ID BIGINT NOT NULL, FROM_ID
BIGINT NOT NULL, PRIMARY KEY (ID));
CREATE TABLE NODE (ID BIGSERIAL NOT NULL, PRIMARY KEY (ID));

** Result:
Exception Description: An incompatible mapping has been encountered
between [class org.jenmo.core.domain.Node] and [class
org.jenmo.core.domain.Edge]. This usually occurs when the cardinality of a
mapping does not correspond with the cardinality of its backpointer.
at
org.eclipse.persistence.exceptions.ValidationException.inval idMapping(ValidationException.java:1183)
at
org.eclipse.persistence.internal.jpa.metadata.accessors.mapp ings.ManyToManyAccessor.process(ManyToManyAccessor.java:115)
at
org.eclipse.persistence.internal.jpa.metadata.accessors.mapp ings.RelationshipAccessor.processRelationship(RelationshipAc cessor.java:404)
at
org.eclipse.persistence.internal.jpa.metadata.MetadataProjec t.processRelationshipAccessors(MetadataProject.java:845)
at
org.eclipse.persistence.internal.jpa.metadata.MetadataProjec t.processStage2(MetadataProject.java:738)
at
org.eclipse.persistence.internal.jpa.metadata.MetadataProces sor.processORMMetadata(MetadataProcessor.java:442)
at
org.eclipse.persistence.internal.jpa.deployment.PersistenceU nitProcessor.processORMetadata(PersistenceUnitProcessor.java :297)
at
org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl. predeploy(EntityManagerSetupImpl.java:834)

Thanks a lot for your help.

andiqo
Re: mapping problem: entity as join table [message #386053 is a reply to message #386050] Sun, 22 March 2009 21:36 Go to previous messageGo to next message
andiqo  is currently offline andiqo Friend
Messages: 32
Registered: July 2009
Member
Up?

I try to persist a graph in database with this mapping, but I always get
the exception... I am using 2.0.0 Milestone.

Regards,
andiqo
Re: mapping problem: entity as join table [message #386057 is a reply to message #386050] Mon, 23 March 2009 13:51 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You are using a "mappedBy" in your ManyToMany mapping to set the inverse,
the inverse of a ManyToMany is always a ManyToMany, but you have it set to
a ManyToOne. I think you want to use a OneToMany not a ManyToMany. A
ManyToMany mapping always uses a join table.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: mapping problem: entity as join table [message #386064 is a reply to message #386057] Mon, 23 March 2009 20:48 Go to previous message
andiqo  is currently offline andiqo Friend
Messages: 32
Registered: July 2009
Member
Thanks a lot for your answer James!

What I want is a ManyToMany relationship between my Node entity and my
Node entity (!). And I also want the join table being my Edge entity...
How can I achieve that in eclipselink ?

Regards,
andiqo
Previous Topic:weaving or not
Next Topic:How to configure query cache invalidation with JPA queries?
Goto Forum:
  


Current Time: Fri Apr 19 05:38:49 GMT 2024

Powered by FUDForum. Page generated in 0.02259 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top