@Entity(access=AccessType.FIELD)
@Table(name="my_brand", schema="ds")
public class Brand {
@Id(generate=GeneratorType.NONE)
@Column(name="brand_code")
private String id;
@Column(name="brand_name")
private String name;
/**
* @param args
*/
public static void main(String[] args) {
Configuration cfg = new AnnotationConfiguration()
.configure();
SessionFactory factory = cfg.buildSessionFactory();
Session session = factory.openSession();
try{
Brand b = (Brand)session.createQuery(
"select b from Brand as b")
.setMaxResults(1)
.uniqueResult();
System.out.println(b.getName());
}finally{
session.close();
}
}
//getters and setters
}
Friday, July 29, 2005
EJB3
With the use of Java 5's new metadata support and Hibernate 3's early annotation tools I decided to see what it would take to make an EJB3 Entity Bean. Well it's quite a bit simpler than Entity EJBs used to be and I don't need a big nasty EJB container either! It's just a plain old Java object (POJO). And as you can see in the main method's source code, I can still use the same Hibernate code that I'm familiar with.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment