Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating an instance variable of a database table type for persistance

 
Yves Somme
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1557
5
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Yves Somme
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1557
5
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic