Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is POJO entity ?

 
alfred jones
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • 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 ?
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 197
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. It is database table name.
 
alfred jones
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • 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 ?
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • 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 Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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 Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic