java - Foreign key is also part of the primary key -


Is it possible to use a foreign key in plain JPA or JPA + hibernate extensions, which can also be used as the primary primary key Is part of? @TableGenerator (name = "test", table = "third", pkColumnName = "a", valueColumnName = "b", pkColumnValue = "first") @Entity Public Class First {@ id @ Generated Values ​​(strategy = generation type. TABLE, generator = "test") protected A A; @OneToMany (mapped = "before", cascade = cascade type. PERSIST) @ colored columns (name = "A") secure list & lt; Seconds & gt; Seconds; } Class IDC implies Serializable {// @ Column (name = "a", insertable = false, updatable = false) protected int a; Protected Beat; } @ Entity ID number (IDC class) public class second {@Id // @ Column (name = "a", insertable = false, updatable = false) protected int a; @ Id protected protected b; @ManyToOne @JoinColumn (name = "a" / *, insertable = false, updatable = false * /) first ago; }

Main:

  public class persister {public static zero main (string [] args) {first aFirst = new first (); Second one second = new second (); ASecond.b = 300; & Lt; Second & gt; Scnds = new arreelist & lt; Seconds & gt; (); Scnds.add (aSecond); AFirst.seconds = scnds; Aecond.first = aFirst; AEntityManager.getTransaction () start () .; AEntityManager.persist (aFirst); Committed to aEntityManager.getTransaction (). }}  

The problem class is in "seconds":

If I set the "insertable = false, updatable = false" field to "a", then this Exceptions are thrown:

"Parameter indicator is not between valid values ​​of values ​​4 and 1 outside range."

And if I say "insertable = false, updateable @manyToOne, set in relation to = false ", it is running but set to" a "on the table" seconds "set

: Set the generated value of first.a in Second.a.

/// //////////////////////////

SQL to create DB: < / P>

Create tables first (an int, primary key (A));

Create another table (an int, b int, primary key (A, B));

Please make the table third (a varchar

please

please

in Thanax Advance

First of all, do you need to make sure? ...

Anyway, I can show my ignorance here but I think you can be quite close, but there is no order of things.

Reading the generated key can be done like this:

  ... before First = new first (); entityManager.save (first); //  

Have you read this?

It does not have a JPA, but if your lucky hibernate can support both an @ ID and @ManyToOne tag on the same area, have you tried it? It would be nice :-) ...

< Pre> @ id / not working Maybe @ManyToOne // joint column (name = "A") before;

Oh and what's all about "one" prefix? Argument? unclear? Ambivalent? One-Enterprisy-talk?


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -