• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

is it the correct mapping?

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic