• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

what is POJO entity ?

 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this code in tutorial for EJB 3.0 entities.

@Entity
@Table(name="bookbank")
public class BookBank implements Serializable {
long id;
String title;
String author;
double price;


what is "bookbank"? is it the database table name ?
 
Ranch Hand
Posts: 198
Oracle 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 database table name.
 
alfred jones
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prabhakar Reddy Bokka wrote:Yes. It is database table name.



I have table name as tbl_book_bank ..... I'm worried because my table name has underscore _ symbol....... is it allowed ?



How do you put primary key and foreign key in entity class ? Is it required or container will do this for me ?
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

alfred jones wrote:

I have table name as tbl_book_bank ..... I'm worried because my table name has underscore _ symbol....... is it allowed ?



It is allowed. All my tables have them.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

alfred jones wrote:
How do you put primary key and foreign key in entity class ? Is it required or container will do this for me ?



you need to specify primary key with an Id annotation:


read all about how to do foriegn keys here under the mapping headings :
http://docs.oracle.com/cd/B25221_05/web.1013/b14428/cmp30cfg.htm#BCGDBFFA
 
alfred jones
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you made a typo ? Is not Id annotation should be placed before a field property ? You have put before getter mehod.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works in both places. I don't have a preference either way, but you should stick to one way
 
alfred jones
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
I will have a database autoincrement id. Do i need to keep an id field in entity class?
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

alfred jones wrote:Thanks.
I will have a database autoincrement id. Do i need to keep an id field in entity class?



Yes, if you read the documentation I linked to, you will see that there are extra annotations for letting EJB know that the database will generate autoincrement id.
 
alfred jones
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim McGuire wrote:

alfred jones wrote:Thanks.
I will have a database autoincrement id. Do i need to keep an id field in entity class?



Yes, if you read the documentation I linked to, you will see that there are extra annotations for letting EJB know that the database will generate autoincrement id.



Ok. I have visited the link . Its very much confusing.

I see it has @GeneratedIdTable and @TableGenerator annotation . I am not yet sure which particular annotation will fit my requirement for database autoincrement id .

Are both annotations doing same thing ?
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just realized the documentation I linked to is for OC4J, which has a subset of the annotations. In other words, forget that link

If you are like me and have an object in your database called a "sequence", then you want something like this:



 
alfred jones
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim McGuire wrote:I just realized the documentation I linked to is for OC4J, which has a subset of the annotations. In other words, forget that link

If you are like me and have an object in your database called a "sequence", then you want something like this:





You have ...

generator = "hch_sequence"
name = "hch_sequence"
sequenceName = "hch_sequence"

Do I need keep all similar names ? if not which names could be different ?


However, I dont have "sequence". MySQL does not support sequence. I have put id field as auto increment in MySQL database. Is it not possible using JPA in MySQL ?
 
alfred jones
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

alfred jones wrote:

Tim McGuire wrote:I just realized the documentation I linked to is for OC4J, which has a subset of the annotations. In other words, forget that link

If you are like me and have an object in your database called a "sequence", then you want something like this:





You have ...

generator = "hch_sequence"
name = "hch_sequence"
sequenceName = "hch_sequence"

Do I need keep all similar names ? if not which names could be different ?


However, I dont have "sequence". MySQL does not support sequence. I have put id field as auto increment in MySQL database. Is it not possible using JPA in MySQL ?



comments please
 
Attractive, successful people love this tiny ad:
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