For the context, client-side I use the MVP pattern, so the view with the One
list knows only the ID, and when my new Many
is received on the server, I want to be able to just update the One
's foreign key, with a "setOneId" or an empty One
object with an ID set to the wanted value.
So I try to create a many-to-one unidirectional in DataNucleus, and I'm struggling a bit. I'm ok to use JDO or JPA, I don't really care. In JPA, I tried this :
@Entity
public class Many {
@Id
String id;
@ManyToOne
@Join(name = "idOne")
One one;
}
@Entity
public class One {
@Id
String id;
}
It's almost what I want. The one-to-many is created but with a join table. I want to have a direct relation. And when I insert/update a Many
, I don't want to insert/update the related One
, just update the idOne
with the good id in my Many
object.
I found this blogpost, but it's with Hibernate, and I think it still use a join table :
@Entity
public class Many {
@Id
public String id;
@Column(name="idOne")
private String idOne;
@ManyToOne
@JoinColumn(name="idOne", nullable=false, insertable=false, updatable=false)
private One one;
}
I tried it, but I got exactly this error.
I don't understand how I am struggling with that. My goal is to have a table that keep some reference data (like a list of country as the class One
), and a list of "working item" (like a town as the class Many
) that I create/update without create/update the reference data, just its foreign key in the Many
object.