This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes creating an instance variable of a database table type for persistance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "creating an instance variable of a database table type for persistance" Watch "creating an instance variable of a database table type for persistance" New topic
Author

creating an instance variable of a database table type for persistance

Yves Somme
Greenhorn

Joined: Apr 30, 2012
Posts: 6
Hi

I have hit a brick wall in my understanding of associations and using them. it may be an over-active brain but there seems so many possibilities. I want 2 instances of a java class/DB table as instance variable of a second class/DB Table. basically I want each Dog instance variable in Race to hold one instance of a Dog, I have tried various combinations of @OneToOne @OneToMany and @ManyToOne but it crashes every time:

here are the 2 classes:




[Added code tags - see UseCodeTags for details]
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1502
    
    5

Hello Yves Somme,

Welcome to CodeRanch!

Please UseCodeTags. It becomes difficult to read non-indented and non-formatted code. Edit : Thanks for adding code tags.

Secondly, CarefullyChooseOneForum. This question seems to be suited for EJB forum. You can request forum admin to transfer this thread there (instead of creating another thread).

Also, please TellTheDetails - 'but it crashes every time' doesn't give a clear idea about exactly what is happening.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Yves Somme
Greenhorn

Joined: Apr 30, 2012
Posts: 6
Thanks for the advice.

I am a novice and tryng to learn from books and the net , but have got to a stage where there are so many examples that I don't know which to choose, I'm out of my depth because I don't know what should happen or even if what I am tryng to do is possible.it seems like it should.

If you think it would be better in the EJB thats fine by me, but please could you explain how I get admin to move it.

Thanks
YS
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1502
    
    5

Hi Yves Somme,

The admin has already moved the thread to 'Object Relational Mapping' forum(check out the forum title at the top), so all you need to do now is - TellTheDetails - i.e. what exactly is the problem.
Yves Somme
Greenhorn

Joined: Apr 30, 2012
Posts: 6
Hi

What I am trying to do is to use an instance of the dog class/database as an instance variable in the race class.

there will be a lot of dogs in the database, but only one of them will be a winner and one of them in second place in each race. I want to be able to store each of those dogs as an instance variable of type dog in an instance of race.
I get an error of Entity not defined if I leave the variables without anything before them.

I have tried
@OneToOne,
@OneToOne(mappedBy = "Dog")
@OneToOne(mappedBy = "dogID");
@OneToOne(mappedBy = "Dogs_ID");
@OneToOne(mappedBy = "DOGS");
@OneToMany
@OneToMany(mappedBy = "Dog")
@OneToMany(mappedBy = "Dog_ID")
@OneToMany(mappedBy = "DOGS")
@OneToMany(mappedBy = "dogID")
@ManyToOne mappedBy wouldn't work on that
I have tried
@JoinColumn( name = "dogID")
@JoinColumn( name = "dog_dogID")
@JoinColumn( name = "DOGS_ID")
@JoinColumn( name = "DOGS_dogID")
but the log says it cannot find "columnname"

I can't figure out what the relationship should be.
I want one dog from many but not one specific dog record which can be pointed to in advance,
I don't want many dogs as there will only be one for each variable,
there will be one race to many dogs but I only want one of the dogs for each instance.
There will be some dogs for each race but many dogs for all of the races, I want one dog from the some dogs.
Brain in overdrive and going nowhere. help.

I can't produce the rest of the code until I have somewhere to store the winner and runner-up.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: creating an instance variable of a database table type for persistance
 
Similar Threads
"hibernate.hbm2ddl.auto">create - to generate DB Tables
One to many mapping problem
Multiple Column Join
Hibernate adding .value,.count,.offset, and hash to query
Possible to find relationship