Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.Id;
- import javax.persistence.Table;
- /**
- * TODO: Enter Javadoc
- */
- @Entity
- @Table(name = "car_product")
- public class CarProduct {
- //~ Instance fields ------------------------------------------------------------------------------------------------
- @Column(name = "car_id")
- private String carid;
- @Column(name = "product_id")
- private String productid;
- @Column(name = "attribute")
- private String attribute;
- @Column(name = "value")
- private String value;
- //~ Constructors ---------------------------------------------------------------------------------------------------
- /**
- * Creates a new CarProduct object.
- */
- public CarProduct() {
- }
- //~ Methods --------------------------------------------------------------------------------------------------------
- public String getAttribute() {
- return attribute;
- }
- public void setAttribute(String attribute) {
- this.attribute = attribute;
- }
- public String getCarid() {
- return carid;
- }
- public void setCarid(String carid) {
- this.carid = carid;
- }
- public String getProductid() {
- return productid;
- }
- public void setProductid(String productid) {
- this.productid = productid;
- }
- public String getValue() {
- return value;
- }
- public void setValue(String value) {
- this.value = value;
- }
- }
- public static void main(String[] args) throws SQLException {
- SessionFactory sessionFactory;
- ServiceRegistry serviceRegistry;
- Configuration config = new Configuration();
- config.configure();
- serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
- sessionFactory = config.buildSessionFactory(serviceRegistry);
- Session session = sessionFactory.getCurrentSession();
- session.beginTransaction();
- // I have to specify the package name too and it is really annoying but it throws an error if just do "from CarProduct".
- List<CarProduct> carProducts = session.createQuery("from com.searchresults.CarProduct").list();
- System.out.println("THE SIZE OF THE LIST IS: " + carProducts.size());
- session.getTransaction().commit();
- }
- <?xml version='1.0' encoding='utf-8'?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD//EN"
- "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
- <property name="connection.url">None of your business</property>
- <property name="connection.username">None of your business</property>
- <property name="connection.password">None of your business</property>
- <!-- JDBC connection pool settings ... using built-in test pool -->
- <property name="connection.pool_size">1</property>
- <!--Select our SQL dialect -->
- <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
- <!-- Print our the SQL to console -->
- <property name="show_sql">true</property>
- <!-- Set the current session context -->
- <property name="current_session_context_class">thread</property>
- <!-- DB schema will be updated if needed -->
- <!-- <property name="hbm2ddl.auto">update</property> -->
- </session-factory>
- </hibernate-configuration>
- <mapping class="CarProduct"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement