Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. import javax.persistence.Column;
  2. import javax.persistence.Entity;
  3. import javax.persistence.Id;
  4. import javax.persistence.Table;
  5.  
  6.  
  7. /**
  8. * TODO: Enter Javadoc
  9. */
  10. @Entity
  11. @Table(name = "car_product")
  12. public class CarProduct {
  13.  
  14. //~ Instance fields ------------------------------------------------------------------------------------------------
  15.  
  16. @Column(name = "car_id")
  17. private String carid;
  18.  
  19. @Column(name = "product_id")
  20. private String productid;
  21.  
  22. @Column(name = "attribute")
  23. private String attribute;
  24.  
  25. @Column(name = "value")
  26. private String value;
  27.  
  28. //~ Constructors ---------------------------------------------------------------------------------------------------
  29.  
  30. /**
  31. * Creates a new CarProduct object.
  32. */
  33. public CarProduct() {
  34. }
  35.  
  36. //~ Methods --------------------------------------------------------------------------------------------------------
  37.  
  38. public String getAttribute() {
  39. return attribute;
  40. }
  41.  
  42. public void setAttribute(String attribute) {
  43. this.attribute = attribute;
  44. }
  45.  
  46. public String getCarid() {
  47. return carid;
  48. }
  49.  
  50. public void setCarid(String carid) {
  51. this.carid = carid;
  52. }
  53.  
  54. public String getProductid() {
  55. return productid;
  56. }
  57.  
  58. public void setProductid(String productid) {
  59. this.productid = productid;
  60. }
  61.  
  62. public String getValue() {
  63. return value;
  64. }
  65.  
  66. public void setValue(String value) {
  67. this.value = value;
  68. }
  69. }
  70.  
  71. public static void main(String[] args) throws SQLException {
  72. SessionFactory sessionFactory;
  73. ServiceRegistry serviceRegistry;
  74.  
  75. Configuration config = new Configuration();
  76. config.configure();
  77. serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
  78. sessionFactory = config.buildSessionFactory(serviceRegistry);
  79. Session session = sessionFactory.getCurrentSession();
  80. session.beginTransaction();
  81.  
  82. // I have to specify the package name too and it is really annoying but it throws an error if just do "from CarProduct".
  83. List<CarProduct> carProducts = session.createQuery("from com.searchresults.CarProduct").list();
  84. System.out.println("THE SIZE OF THE LIST IS: " + carProducts.size());
  85.  
  86. session.getTransaction().commit();
  87.  
  88.  
  89. }
  90.  
  91. <?xml version='1.0' encoding='utf-8'?>
  92. <!DOCTYPE hibernate-configuration PUBLIC
  93. "-//Hibernate/Hibernate Configuration DTD//EN"
  94. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  95. <hibernate-configuration>
  96. <session-factory>
  97. <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
  98. <property name="connection.url">None of your business</property>
  99. <property name="connection.username">None of your business</property>
  100. <property name="connection.password">None of your business</property>
  101.  
  102. <!-- JDBC connection pool settings ... using built-in test pool -->
  103. <property name="connection.pool_size">1</property>
  104.  
  105. <!--Select our SQL dialect -->
  106. <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
  107.  
  108. <!-- Print our the SQL to console -->
  109. <property name="show_sql">true</property>
  110.  
  111. <!-- Set the current session context -->
  112. <property name="current_session_context_class">thread</property>
  113.  
  114. <!-- DB schema will be updated if needed -->
  115. <!-- <property name="hbm2ddl.auto">update</property> -->
  116. </session-factory>
  117. </hibernate-configuration>
  118.  
  119. <mapping class="CarProduct"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement