hibernate question

C

Chris Smith

gk said:
in hibernate
(http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html)

there is a class

import java.util.Date;

public class Event {
private Long id; // i dont have a coulmn with name "id" in my
DB...should i keep this ?

private String title;
private Date date;

What is the primary key for the database table, then? You'll need some
kind of primary key for any table that is mapped as a Hibernate entity.
You will also need a field in the corresponding class, which will
contain that database attribute.

The names don't matter, if that's what you're asking. In the mapping
file, you can specify the name of the field and the name of the database
attribute, and they do not need to match.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
G

gk

so,that means , if i have 5 columns in the DB . then class should have
5 member variable . no less no more . correct ?

in fact , i was asking whether this "id" has to be added as a
additional thing apart from the DB columns.

but as you told , there is no additional member variable . all
represents the DB column. so it is fine.

Thank you
 
A

Adam Maass

gk said:
so,that means , if i have 5 columns in the DB . then class should have
5 member variable . no less no more . correct ?

No, not exactly. For the simpler cases, this is generally true. But you
could have multiple columns in the database, represented by a single object
in memory: columns STREET, CITY, ZIP might map to a single class Address.
Likewise, you might not bother to map some of the columns; maybe you don't
need them in memory for what you want to do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top