Foreign Key Constraint

523 views
Skip to first unread message

Abhishek Mahawar

unread,
Aug 11, 2011, 3:06:06 PM8/11/11
to play-framework
Hi,

I am facing problems in applying a foreign key constraint for a
entity. Is there a place where I can find good explanation of
constrains that can be applied . Any kind of help will be appreciated.

Sebastien Cesbron

unread,
Aug 12, 2011, 1:48:26 AM8/12/11
to play-fr...@googlegroups.com
Hi

FK constraint are not in the scope of play but are a matter of db (and a bit of jpa, depends on what is your problem). You can find more informations from doc on these products

Regards
Seb

2011/8/11 Abhishek Mahawar <mahawa...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


Abhishek Mahawar

unread,
Aug 12, 2011, 1:51:36 AM8/12/11
to play-framework
Hi,

The exact problem that I am facing is quoted below
"A JPA error occurred (Unable to build EntityManagerFactory):
collection foreign key mapping has wrong number of columns:
models.License.value type: component[id,id]" . I ma not able to find
nyhing related on web. Any idea as to what is the problem here. The
corresponding model classes are given below:-


package models;

import java.util.*;
import javax.persistence.*;

import play.data.validation.*;
import play.db.jpa.*;

@Entity
public class Property extends Model {
@Id
String name;
String type;
@OneToMany
List<Value> value;
public Property(String name, String type) {
this.name = name;
this.type = type;
value = new ArrayList<Value>();
}

}

package models;

import java.util.*;
import javax.persistence.*;

import play.data.validation.*;
import play.db.jpa.*;

@Entity
public class Value extends Model{
String value;
public Value(String value){
this.value = value;
}
}

package models;

import java.util.*;
import javax.persistence.*;

import play.data.validation.*;
import play.db.jpa.*;

@Entity
public class License extends Model {
@Id
Long id;
@OneToMany
List<Value> value;
public License(Long id){
this.id = id;
value = new ArrayList<Value>();
}

}

Thanks

On Aug 12, 10:48 am, Sebastien Cesbron <scesb...@gmail.com> wrote:
> Hi
>
> FK constraint are not in the scope of play but are a matter of db (and a bit
> of jpa, depends on what is your problem). You can find more informations
> from doc on these products
>
> Regards
> Seb
>
> 2011/8/11 Abhishek Mahawar <mahawar.a...@gmail.com>

Sebastien Cesbron

unread,
Aug 12, 2011, 2:02:08 AM8/12/11
to play-fr...@googlegroups.com
Hi

You put a @Id on your name column. This name is not the identifier of your object. Just delete this annotation and I think everything will be ok

Regards
Seb

2011/8/12 Abhishek Mahawar <mahawa...@gmail.com>

Abhishek Mahawar

unread,
Aug 12, 2011, 2:46:11 AM8/12/11
to play-framework
HI,
Seb ,it's not working even after removing @Id on name column

On Aug 12, 11:02 am, Sebastien Cesbron <scesb...@gmail.com> wrote:
> Hi
>
> You put a @Id on your name column. This name is not the identifier of your
> object. Just delete this annotation and I think everything will be ok
>
> Regards
> Seb
>
> 2011/8/12 Abhishek Mahawar <mahawar.a...@gmail.com>

Sebastien Cesbron

unread,
Aug 12, 2011, 2:52:20 AM8/12/11
to play-fr...@googlegroups.com
License also have an id which is duplicate with the models one.

You also have two entities (License and Property) that points to the same entity Value which causes to foreign keys with the same name on this table.

Check deeper the jpa documentation to see how to configure columns name. You may also have to do some modelization of your domain to check that everything is ok.

Regards
Seb

2011/8/12 Abhishek Mahawar <mahawa...@gmail.com>
Reply all
Reply to author
Forward
0 new messages