hey guys
Im a swiss student and my english is not that good and ive never posted in your forum, so thats why im sorry if im doing any mistakes, but i have big trouble, because ive to get this straight till end of week. i uploaded also all classes but if u see the problem in the main problem field the classes are copied after the problem description.
the structure:
the Squad class has a Collection which stores Athlete Objects, the Athlet has another embeddedCollection of Marks and another embedded Association, furthermore the athlete is inherited by a Person.
the problem:
I tested the hole Athlete structure and it works, but if i want to extend my program with putting the Athletes into a squad it brings up an exception. so the problematic line would u find int the main class line number 19 squad.setAthlets(x);
my Exception:
Exception in thread "main" [ObjectDB 2.2.0] javax.persistence.RollbackException Failed to commit transaction: Failed to write the value of field test.Squad.athlets using reflection: Attempt to persist a reference to a non managed 'test.Athlet' instance (error 613) at com.objectdb.jpa.EMImpl.commit(EMImpl.java:259) at test.Main.main(Main.java:25) Caused by: com.objectdb.o._PersistenceException: Failed to write the value of field test.Squad.athlets using reflection: Attempt to persist a reference to a non managed 'test.Athlet' instance at com.objectdb.o.JPE.g(JPE.java:138) at com.objectdb.o.ERR.f(ERR.java:59) at com.objectdb.o.OBM.bF(OBM.java:827) at com.objectdb.o.OBM.bD(OBM.java:711) at com.objectdb.jpa.EMImpl.commit(EMImpl.java:256) ... 1 more Caused by: com.objectdb.o.UserException: Failed to write the value of field test.Squad.athlets using reflection: Attempt to persist a reference to a non managed 'test.Athlet' instance at com.objectdb.o.MSG.d(MSG.java:74) at com.objectdb.o.UMR.M(UMR.java:834) at com.objectdb.o.UMR.x(UMR.java:527) at com.objectdb.o.UML.u(UML.java:517) at com.objectdb.o.MMM.ae(MMM.java:1006) at com.objectdb.o.UTY.aF(UTY.java:1181) at com.objectdb.o.UTY.aE(UTY.java:1170) at com.objectdb.o.ENH.a(ENH.java:46) at com.objectdb.o.STA.T(STA.java:512) at com.objectdb.o.STM.C(STM.java:386) at com.objectdb.o.OBM.bG(OBM.java:876) at com.objectdb.jdo.PMImpl.bG(PMImpl.java:2185) at com.objectdb.o.OBM.bF(OBM.java:792) ... 3 more Caused by: com.objectdb.o.UserException: Attempt to persist a reference to a non managed 'test.Athlet' instance at com.objectdb.o.MSG.d(MSG.java:61) at com.objectdb.o.TYW.writeElement(TYW.java:246) at com.objectdb.o.ABT.writeArray(ABT.java:527) at com.objectdb.o.CLT.writeStrictly(CLT.java:187) at com.objectdb.o.TYW.ar(TYW.java:382) at com.objectdb.o.TYW.au(TYW.java:431) at com.objectdb.o.TYW.writeElement(TYW.java:259) at com.objectdb.o.UMR$P.y(UMR.java:902) at com.objectdb.o.UMR.x(UMR.java:524) ... 13 more
that are my classes:
first the Squad class: package test; import java.util.LinkedList; import java.util.List; import javax.persistence.Entity; import javax.persistence.OneToMany; @Entity public class Squad { private int squadId; @OneToMany() private List<Athlet> athlets; public Squad() { super(); // TODO Auto-generated constructor stub } public Squad(int squadId) { super(); this.squadId = squadId; athlets = new LinkedList<Athlet>(); } public void addAthlete(Athlet athlet) { athlets.add(athlet); } public int getSquadId() { return squadId; } public void setSquadId(int squadId) { this.squadId = squadId; } public List<Athlet> getAthlets() { return athlets; } public void setAthlets(Athlet athlet) { this.athlets.add(athlet); } }
Now the Athlete Class
package test; import java.io.Serializable; import java.util.HashMap; import java.util.Map; import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; @Entity public class Athlet extends Person implements Serializable { /** * */ private static final long serialVersionUID = 1L; @Id @GeneratedValue private long id; private int squadId; private int athletId; public long getId() { return id; } public void setId(long id) { this.id = id; } private String prgClass; private int yearOfBirth; @OneToMany private Map<DeviceType, Mark> marks; @Embedded private Association association; public Athlet() { super("a", "b", "c"); } public Athlet(int squadID, int athletID, String prgClass, String vorname, String name, String adresse, int yearOfBirth, Association verein) { super(name, vorname, adresse); this.squadId = squadID; this.athletId = athletID; this.prgClass = prgClass; this.yearOfBirth = yearOfBirth; this.association = verein; marks = new HashMap<DeviceType, Mark>(); marks.put(DeviceType.FLOOR_EXCERCISE, new Mark(4, 3, 4, 3, 4, 3, 4)); } Athlet(int x, int y, String c) { super("a", "b", c); this.squadId = x; this.athletId = y; marks = new HashMap<DeviceType, Mark>(); marks.put(DeviceType.FLOOR_EXCERCISE, new Mark(4, 3, 4, 3, 4, 3, 4)); association = new Association(); } public int getSquadId() { return squadId; } public void setSquadId(int squadId) { this.squadId = squadId; } public int getAthletId() { return athletId; } public void setAthletId(int athletId) { this.athletId = athletId; } public String getPrgClass() { return prgClass; } public void setPrgClass(String prgClass) { this.prgClass = prgClass; } public int getYearOfBirth() { return yearOfBirth; } public void setYearOfBirth(int yearOfBirth) { this.yearOfBirth = yearOfBirth; } @Override public String toString() { return String.format("(%d, %d)", this.squadId, this.athletId); } }
Thanks for ur help