• Post Reply Bookmark Topic Watch Topic
  • New Topic

is it the correct mapping?

 
mark smith
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i'm begin in JEE, i would like to do mapping between ejb

class user
-----------
us_id
us_username

class ads
----------
ad_id
ad_name

an user can have 1 or many ads
an ads can be linked to only one user

my code

my class User


my class Ads


i would like to know if it's ok, if there are better way to doing that..

thanks
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It strains my brain to see Java coded like a database. I suggest using standard java naming conventions.

If you have a pre-existing database, or you have imposed naming standards for your database, you should use the @Column annotation to define the column name.

Also, my personal preference is for annotations on the fields instead of the accessors. Puts all the information at the top of the class.

Note that some tools will require both getter/setter whether you really want that to be the contract or not.

@OneToMany
private Collection<Ads> ads;

@Column(name="us_id")
private long id;

@Column(name="us_username");
private username;

@Column(name="us_password");
private password;


Of course, you left off password from this, and I would exclude the "id", it's not really part of the class, but an affectation of the implementation (unless this was supposed to represent a table and not a class):

class user
-----------
us_username
us_password
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!