Skip to main content

Simple OneToOne mapping not working

2 replies [Last post]
stefanarentz
Offline
Joined: 2006-05-23

I have a really Simple OneToOne mapping that comes straight out of the book and JPA spec. But it is not working. No idea why. Hope someone here can give me a clue.

I have a User that references an ActivationCode:

@Entity
public class User {
@Id @GeneratedValue(strategy= GenerationType.AUTO)
public int getId()
{
return mId;
}

public void setId(int id)
{
mId = id;
}

private ActivationCode mActivationCode;

@OneToOne(cascade = CascadeType.ALL)
public ActivationCode getActivationCode()
{
return mActivationCode;
}

public void setActivationCode(ActivationCode activationCode)
{
mActivationCode = activationCode;
}
}

@Entity
public class ActivationCode {
private int mId = -1;

@Id @GeneratedValue(strategy= GenerationType.AUTO)
public int getId()
{
return mId;
}

public void setId(int id)
{
mId = id;
}

private User mUser;

@OneToOne(mappedBy = "activationCode")
public User getUser()
{
return mUser;
}

public void setUser(User user)
{
mUser = user;
}
}

When I deploy this I get

Exception [TOPLINK-94] (Oracle TopLink Essentials - 2006.5 (Build 060511)): oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: Descriptors must have a table name defined.
Descriptor: RelationalDescriptor(nl.foo.core.entities.ActivationCode --> [])

Exception [TOPLINK-74] (Oracle TopLink Essentials - 2006.5 (Build 060511)): oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: The primary key fields are not set for this descriptor.
Descriptor: RelationalDescriptor(nl.foo.core.entities.ActivationCode --> [])

Exception [TOPLINK-108] (Oracle TopLink Essentials - 2006.5 (Build 060511)): oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: Cannot find value in class indicator mapping in parent descriptor [null].
Descriptor: RelationalDescriptor(nl.foo.core.entities.ActivationCode --> [])

I don't understand this at all. This should be a trivial mapping.

This is with toplink essentials v2b06

S.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ss141213
Offline
Joined: 2005-03-30

There is nothing wrong with your Java code except that User.java does not define "int mId" field. But, that has to be an error introduced while posting this message, else your code won't compile.

Looking at the error message, I think, [b]TopLink is not treating nl.foo.core.entities.ActivationCode as an entity[/b].
If you are using true in your persistence.xml, then you must ensure that all entity classes are also mentioned in persistence.xml file.

If you are still not able to figure out, can you supply your persistence.xml file?

Hope this helps,
Sahoo

stefanarentz
Offline
Joined: 2006-05-23

Thank you very much for the hint. It was a long day for me and I indeed completely missed the tag in persistence.xml for ActivationCode.

Dohhh.

Maybe a new toplink error can be introduced; 'referenced class is not defined as a persistent object' or so :-)

S.