File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes what is  POJO entity ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "what is  POJO entity ?" Watch "what is  POJO entity ?" New topic
Author

what is POJO entity ?

alfred jones
Ranch Hand

Joined: Apr 19, 2005
Posts: 279
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

Joined: Jul 26, 2005
Posts: 189

Yes. It is database table name.


SCJP 5, SCWCD 5
alfred jones
Ranch Hand

Joined: Apr 19, 2005
Posts: 279
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

Joined: Apr 30, 2003
Posts: 820

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

Joined: Apr 30, 2003
Posts: 820

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

Joined: Apr 19, 2005
Posts: 279
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
Bartender

Joined: Jan 17, 2008
Posts: 2052
    
  22

It works in both places. I don't have a preference either way, but you should stick to one way
alfred jones
Ranch Hand

Joined: Apr 19, 2005
Posts: 279
Thanks.
I will have a database autoincrement id. Do i need to keep an id field in entity class?
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

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

Joined: Apr 19, 2005
Posts: 279
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

Joined: Apr 30, 2003
Posts: 820

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

Joined: Apr 19, 2005
Posts: 279
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

Joined: Apr 19, 2005
Posts: 279
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is POJO entity ?
 
Similar Threads
Empty String default in API of annotations
Annotations doubt
Automatic table creation
Please explain this @OneToOne
Get Table name from entity name