• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

uses a non-entity as target entity in relationship attribute

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the error message I get when I try to run my sample app.

For a one to many bidirectional mapping with many to one on the child. I have both the classes in the same package and listed in persistence.xml.
I am stuck. Any help would be appreciated.

Thanks,
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ensure the target object is annotated with @Entity, is in the same jar file as the persistence.xml, is listed with the correct package in the persistence.xml, and that you have correctly deployed your application.

If still having issues include the fullexception stack trace and source of the class and persistence.xml.
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I have a problem with a one to many bidirectional mapping. I get a java.sql.SQLIntegrigyConstraintViolationException Cannot insert NULL into

example of what I have

@JoinColumn(name = "AuthorNo", referencedColumnName = "AuthorNo")
@ManyToOne
private Authors authorNo;


@OneToMany(mappedBy = "authorNo", cascade=CascadeType.ALL)
private List<Books> booksCollection= new ArrayList<Books>();

I would really appreciate help in fixing this problem
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sonia please post you entity classes entirely and also the part of code where you make the insertion. It will be easier for us and for you to see exactly instead of making assumption of what your problem is.
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Phones.java




Customer.java

TestOneToOne.java


persistence.xml




[/code]
 
Ranch Hand
Posts: 62
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try making Customer your driving entity with the following change..

Phones.java

and
Customer.java
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "TELEPHONENUMBERMANDATORY_PHONES_ID": invalid identifier

 
joy b chakravarty
Ranch Hand
Posts: 62
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
out of curiosity..does this work
try {
em.getTransaction().begin();
em.persist(p);
em.getTransaction().commit();
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. I am still getting an error

... 2 more
Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "TELEPHONENUMBERMANDATORY_PHONES_ID": invalid identifier

 
joy b chakravarty
Ranch Hand
Posts: 62
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops .. i hope when you tried em.persist(p); you used your original code
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes
 
joy b chakravarty
Ranch Hand
Posts: 62
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Had a closer look at your code.
The Customer class has
@Column(name = "PHONES_ID", nullable = false)
private BigDecimal phonesId;

and your Phones class has

@Column(name = "CUSTOMER_ID")
private BigDecimal customerId;

1> Even in bidirectional relationships (an ORM concept) you dont need to have foreign keys in both tables.
2> You dont specify foreign keys in this fashion, you do it using JoinColumn


 
joy b chakravarty
Ranch Hand
Posts: 62
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One to One
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I took it out after I posted the code.

See:

http://forums.oracle.com/forums/thread.jspa?messageID=9645937�
 
joy b chakravarty
Ranch Hand
Posts: 62
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the link you mentioned ...

CUSTOMER.java
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="CUSTOMER_ID", insertable = false, updatable = false)
private Phones telephoneNumberMandatory;

Phones.java
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "telephoneNumberMandatory")
private Customer customer;

The Customer table has the column Phone_ID
The Phone table shouldn't and doesn't not have the column Customer_Id (as its not needed)

So you the way these two tables need to be joined is by the Phone_Id (pk in Phones table and fk in Customer table)

 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IT is a bidirectional oneToOne. That is not where my error is though.

Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "TELEPHONENUMBER_PHONES_ID": invalid identifier

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)


I changed the TelephoneNumberMandatory to TELEPHONENUMBER
 
joy b chakravarty
Ranch Hand
Posts: 62
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it is bidirectional OnetoOne, but the tables in database will have just one foreign key.

CUSTOMER.java
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="CUSTOMER_ID", insertable = false, updatable = false)
private Phones telephoneNumberMandatory

The above indicates that the Customer and Phones needs to be joined by CUSTOMER_ID, in that case the PHONE_ID column in Customer is redundant.
Please try with
@JoinColumn(name="PHONE_ID", insertable = false, updatable = false)

 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@OneToOne(optional = false,cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "PHONE_ID", unique = true, nullable = false, updatable = false)
private Phones telephoneNumber;


is what I have now, I am getting the following error:


eption [EclipseLink-4002] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00904: "TELEPHONENUMBER_PHONES_ID": invalid identifier

Error Code: 904
Call: INSERT INTO PHONES (TELEPHONENUMBER_PHONES_ID, PHONE_NUMBER) VALUES (?, ?)
bind => [101, 5716120000]
Query: InsertObjectQuery(testonetoone.Phones@1ea0105)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)


I really appreciate. need to get it resolved ASAP
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
fixed it. onetoone works! hurrah
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://forums.oracle.com/forums/thread.jspa?threadID=2235014

The onetoone mapping stopped working
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
im having a similar problem with my foreign keys.this is a sample appi have been trying using this particular link

http://netbeans.org/kb/67/java/gui-db-custom.html



but after making changes in the customers and orders class if i try to run the program i get the following error

[class customerrecords.Customers] uses a non-entity [class customerrecords.Countries] as target entity in the relationship attribute [private customerrecords.Countries customerrecords.Customers.countryId].
 
I didn't say it. I'm just telling you what this tiny ad said.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic