# JPA-Persist Problem



## M4A1 (30. Apr 2010)

HAllo,

ich habe ein kleineres Problem, ich versuche mit JPA zwei Klassen zu persisten, das DB-Schema soll dann so aussehen

Ticket: ID, SUBJECT, TEXT
Resolution: ID, Text, Ticket_ID

So, nun habe ich folgende Klassen

In der Klasse Ticket:

```
@OneToMany(cascade=CascadeType.ALL, mappedBy="ticket")
private ArrayList<Resolution> resolutions = null;
```

In der Klasse Resolution:

```
@ManyToOne()
@JoinColumn(name="id", nullable=false, updatable=false)
private Ticket ticket = null;
```

So habe ich das probiert, der Columnname und die Eigenschaft heißen auch wirklich id. Ich bekomme aber immer folgende Fehlermeldung. Wahrscheinlich nur ne Kleinigkeit, aber ich häng da jetzt schon Stunden dran und sehs einfach nicht.
(Nicht erschrecken, habe jetzt einfach mal alles genommen):

```
Exception [EclipseLink-0] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-1] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The attribute [resolutions] is not declared as type ValueHolderInterface, but its mapping uses indirection.
Mapping: org.eclipse.persistence.mappings.OneToManyMapping[resolutions]
Descriptor: RelationalDescriptor(model.Ticket --> [DatabaseTable(TICKET)])

Runtime Exceptions: 
---------------------------------------------------------

	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:477)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:666)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:630)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:229)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:255)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:112)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:164)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:151)
	at testing.CreateDatabase.main(CreateDatabase.java:47)

Descriptor Exceptions: 
---------------------------------------------------------


Local Exception Stack: 
Exception [EclipseLink-1] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The attribute [resolutions] is not declared as type ValueHolderInterface, but its mapping uses indirection.
Mapping: org.eclipse.persistence.mappings.OneToManyMapping[resolutions]
Descriptor: RelationalDescriptor(model.Ticket --> [DatabaseTable(TICKET)])
	at org.eclipse.persistence.exceptions.DescriptorException.attributeAndMappingWithIndirectionMismatch(DescriptorException.java:270)
	at org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy.validateDeclaredAttributeType(BasicIndirectionPolicy.java:362)
	at org.eclipse.persistence.mappings.ForeignReferenceMapping.validateBeforeInitialization(ForeignReferenceMapping.java:1371)
	at org.eclipse.persistence.mappings.CollectionMapping.validateBeforeInitialization(CollectionMapping.java:1510)
	at org.eclipse.persistence.descriptors.ClassDescriptor.validateBeforeInitialization(ClassDescriptor.java:5123)
	at org.eclipse.persistence.descriptors.ClassDescriptor.preInitialize(ClassDescriptor.java:3198)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:429)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:666)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:630)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:229)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:255)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:112)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:164)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:151)
	at testing.CreateDatabase.main(CreateDatabase.java:47)

Runtime Exceptions: 
---------------------------------------------------------

[EL Severe]: Local Exception Stack: 
Exception [EclipseLink-0] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-1] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The attribute [resolutions] is not declared as type ValueHolderInterface, but its mapping uses indirection.
Mapping: org.eclipse.persistence.mappings.OneToManyMapping[resolutions]
Descriptor: RelationalDescriptor(model.Ticket --> [DatabaseTable(TICKET)])

Runtime Exceptions: 
---------------------------------------------------------

	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:477)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:666)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:630)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:229)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:255)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:112)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:164)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:151)
	at testing.CreateDatabase.main(CreateDatabase.java:47)

Descriptor Exceptions: 
---------------------------------------------------------


Local Exception Stack: 
Exception [EclipseLink-1] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The attribute [resolutions] is not declared as type ValueHolderInterface, but its mapping uses indirection.
Mapping: org.eclipse.persistence.mappings.OneToManyMapping[resolutions]
Descriptor: RelationalDescriptor(model.Ticket --> [DatabaseTable(TICKET)])
	at org.eclipse.persistence.exceptions.DescriptorException.attributeAndMappingWithIndirectionMismatch(DescriptorException.java:270)
	at org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy.validateDeclaredAttributeType(BasicIndirectionPolicy.java:362)
	at org.eclipse.persistence.mappings.ForeignReferenceMapping.validateBeforeInitialization(ForeignReferenceMapping.java:1371)
	at org.eclipse.persistence.mappings.CollectionMapping.validateBeforeInitialization(CollectionMapping.java:1510)
	at org.eclipse.persistence.descriptors.ClassDescriptor.validateBeforeInitialization(ClassDescriptor.java:5123)
	at org.eclipse.persistence.descriptors.ClassDescriptor.preInitialize(ClassDescriptor.java:3198)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:429)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:666)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:630)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:229)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:255)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:112)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:164)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:151)
	at testing.CreateDatabase.main(CreateDatabase.java:47)

Runtime Exceptions: 
---------------------------------------------------------

Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-0] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-1] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The attribute [resolutions] is not declared as type ValueHolderInterface, but its mapping uses indirection.
Mapping: org.eclipse.persistence.mappings.OneToManyMapping[resolutions]
Descriptor: RelationalDescriptor(model.Ticket --> [DatabaseTable(TICKET)])

Runtime Exceptions: 
---------------------------------------------------------

	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:272)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:112)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:164)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:151)
	at testing.CreateDatabase.main(CreateDatabase.java:47)
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-1] (Eclipse Persistence Services - 1.1.3.v20091002-r5404): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The attribute [resolutions] is not declared as type ValueHolderInterface, but its mapping uses indirection.
Mapping: org.eclipse.persistence.mappings.OneToManyMapping[resolutions]
Descriptor: RelationalDescriptor(model.Ticket --> [DatabaseTable(TICKET)])

Runtime Exceptions: 
---------------------------------------------------------

	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:477)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:666)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:630)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:229)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:255)
	... 4 more
```

Bitte, hoffentlich kann mir einer helfen. Danke schonmal im voraus.

Gruß

Flo


----------



## musiKk (30. Apr 2010)

Zunächst: Meines Erachtens ist die Join-Spalte in der Tabelle resolution ticket_id und nicht id; das muss auch in [c]@JoinColumn[/c] entsprechend angegeben werden. Dort wird ja nicht die referenzierte Spalte angegeben (das wäre referencedColumnName), sondern die referenzierende.

Der Fehler dürfte aber eher daher rühren, dass Du explizit [c]ArrayList[/c] verwendest und nicht das Interface [c]List[/c].


----------



## M4A1 (30. Apr 2010)

Mensch, klasse. Vielen Dank, da muss man erstmal drauf kommen, das man mit den blöden ArrayList nichts anfangen kann. Hab schon ewig mit rum gemacht.

Gruß 

Flo


----------

