I am new in hibernate. I try to use Hibernate annotation to implement the mapping of the properties with the database. But in my object class, when I import javax.persistence.* it can not be resolved.
I use Eclipse IDE, I add the hibernate-notations.jar, hibernate-commons-notations.jar, hibernate-entitymanager.jar, hibernate3.jar, antlr-2.7.6.jar, dom4j-1.6.1.jar, jta-1.1.jar to my classpath.
and my hibernate configuration file is hibernate.cfg.xml:
Code:<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/test</property> <property name="connection.username">user</property> <property name="connection.password"></property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">none</property> <mapping class="springapp.domain.Product"/> </session-factory> </hibernate-configuration>
My object class is Product.java:
What do I miss?? How to solve the problem?Code:package springapp.domain; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table;//(The red part can not be resolved) @Entity @Table(name = "product") public class Product implements Serializable { @Id @Column(name = "id") private int id; @Column(name = "description") private String description; @Column(name = "price") private Double price; public void setId(int i) { id = i; } public int getId() { return id; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Double getPrice() { return price; } public void setPrice(Double price) { this.price = price; } public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("Description: " + description + ";"); buffer.append("Price: " + price); return buffer.toString(); } }


Reply With Quote
