Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Unique constraints in unidirectional one to one relationship
Unique constraints in unidirectional one to one relationship [message #1327794] Fri, 02 May 2014 10:44
Michał Przybylak is currently offline Michał PrzybylakFriend
Messages: 1
Registered: May 2014
Junior Member
Hello everyone.

I'm learning now about JPA 2.1 with EclipseLink as the JPA Provider, and I have following question about unidirectional @OneToOne mapping.

In JSR-338 there is a section ("Unidirectional OneToOne Relationshps") with following paragraph:

Table A conttains a foreign key to table B. The foreign key column name is formed as the concatenation of the following: the name of the realtionship property or field of entity A; "_"' the name of the primary key column in table B. The foreign key column has the same type as primary key of table B and there is a unique key constraint on it.

This basically means for me that I can assign target entity to only one source entity. In my opinion EclipseLink in version 2.5.1 with Derby database does not follow JSR-338 in such scenario.

Here is code example:

Source entity:

public class FootballPlayer {

	private long id;
	private Ball ball;
	public FootballPlayer() {

	public FootballPlayer(long id) { = id;

	public long getId() {
		return id;

	public void setBall(Ball ball) {
		this.ball = ball;

	public Ball getBall() {
		return ball;

Target entity:

public class Ball {

	private long id;

	public Ball() {
	public Ball(long id) { = id;

	public long getId() {
		return id;

And scenario:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("eclipselink-pu");
EntityManager em = emf.createEntityManager();

Ball ball = new Ball(1L);
FootballPlayer firstPlayer = new FootballPlayer(2L);
FootballPlayer secondPlayer = new FootballPlayer(3L);


em.getTransaction().commit(); // Exception?


Persistence unit definition in persistence.xml
<persistence-unit name="eclipselink-pu" transaction-type="RESOURCE_LOCAL">
			<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
			<property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:eclipselink-test;create=true" />
			<property name="javax.persistence.jdbc.user" value="APP" />
			<property name="javax.persistence.jdbc.password" value="APP" />
			<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
			<property name="eclipselink.logging.level.sql" value="FINE"/>
			<property name="eclipselink.logging.parameters" value="true"/>

When I add:
to ball field in FootballPlayer class - there is an exception as I expect.

So my question is - is there something wrong with my code, or should I report bug?
Previous Topic:Exception when updating object from outside of transaction
Next Topic:Problem removing directory with database
Goto Forum:

Current Time: Thu Oct 08 20:30:52 GMT 2015

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

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