Guest User

Untitled

a guest
Mar 14th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. CREATE TABLE users (
  2. ID INT AUTO_INCREMENT,
  3. FIRSTNAME VARCHAR(100) NOT NULL,
  4. LASTNAME VARCHAR(100) NOT NULL,
  5. AGE INT NOT NULL,
  6. ID_ROLE INT NOT NULL,
  7. ID_LEVEL INT NOT NULL,
  8. PRIMARY KEY (ID)
  9. );
  10. CREATE TABLE roles (
  11. ID INT AUTO_INCREMENT,
  12. ROLE VARCHAR(100) NOT NULL,
  13. );
  14. CREATE TABLE levels (
  15. ID INT AUTO_INCREMENT,
  16. LEVEL VARCHAR(100) NOT NULL,
  17. );
  18.  
  19. public class User {
  20. int id, age;
  21. private String firstname, lastname;
  22. private Role ref_role;
  23. private Level ref_level;
  24.  
  25. public int getId() {
  26. return id;
  27. }
  28. public void setId(int id) {
  29. this.id = id;
  30. }
  31. public int getAge() {
  32. return age;
  33. }
  34. public void setAge(int age) {
  35. this.age = age;
  36. }
  37. public String getFirstName() {
  38. return firstname;
  39. }
  40. public void setFirstName(String firstname) {
  41. this.firstname= firstname;
  42. }
  43. public String getLastName() {
  44. return lastname;
  45. }
  46. public void setLastName(String lastname) {
  47. this.lastname= lastname;
  48. }
  49. public Ruolo getRef_role() {
  50. return ref_role;
  51. }
  52. public void setRef_role(Role ref_role) {
  53. this.ref_ruolo = ref_ruolo;
  54. }
  55. public Livello getRef_level() {
  56. return ref_level;
  57. }
  58. public void setRef_level(Level ref_level) {
  59. this.ref_level= ref_level;
  60. }
  61. public User() {}
  62. }
  63. public class Role {
  64. private int id;
  65. private String role;
  66.  
  67. public int getId() {
  68. return id;
  69. }
  70. public void setId(int id) {
  71. this.id = id;
  72. }
  73. public String getRole() {
  74. return role;
  75. }
  76. public void setRole(String role) {
  77. this.role = role;
  78. }
  79. public Role() {
  80. }
  81. }
  82. public class Level {
  83. private int id;
  84. private String level;
  85.  
  86. public int getId() {
  87. return id;
  88. }
  89. public void setId(int id) {
  90. this.id = id;
  91. }
  92. public String getLevel() {
  93. return level;
  94. }
  95. public void setLevel(String level) {
  96. this.level = level;
  97. }
  98. public Level() {}
  99. }
  100.  
  101. <hibernate-configuration>
  102. <session-factory>
  103. <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  104. <property name="connection.url">jdbc:mysql://localhost:3306/mydatabase</property>
  105. <property name="connection.username">root</property>
  106. <property name="connection.password"></property>
  107. <property name="hibernate.c3p0.min_size">5</property>
  108. <property name="hibernate.c3p0.max_size">20</property>
  109. <property name="hibernate.c3p0.timeout">300</property>
  110. <property name="hibernate.c3p0.max_statements">50</property>
  111. <property name="hibernate.c3p0.idle_test_period">3000</property>
  112.  
  113. <mapping resource="user.hbm.xml"/>
  114. <mapping resource="role.hbm.xml"/>
  115. <mapping resource="level.hbm.xml"/>
  116. </session-factory>
  117. </hibernate-configuration>
  118.  
  119. <hibernate-mapping>
  120. <class name="User" table="users">
  121. <id name="id" column="ID" type="integer">
  122. <generator class="native"/>
  123. </id>
  124. <property name="firstname" column="FIRSTNAME" type="string"/>
  125. <property name="lastname" column="LASTNAME" type="string"/>
  126. <property name="age" column="AGE" type="integer"/>
  127.  
  128. <many-to-one name="ref_role" class="Role" column="ID_ROLE" not-null="true"/>
  129. <many-to-one name="ref_level" class="Level" column="ID_LEVEL" not-null="true"/>
  130. </class>
  131. </hibernate-mapping>
  132.  
  133. <hibernate-mapping>
  134. <class name="Role" table="roles">
  135. <id name="id" column="ID" type="integer">
  136. <generator class="native"/>
  137. </id>
  138. <property name="role" column="ROLE" type="string"/>
  139. </class>
  140. </hibernate-mapping>
  141.  
  142. <hibernate-mapping>
  143. <class name="Level" table="levels">
  144. <id name="id" column="ID" type="integer">
  145. <generator class="native"/>
  146. </id>
  147. <property name="level" column="LEVEL" type="string"/>
  148. </class>
  149. </hibernate-mapping>
  150.  
  151. org.hibernate.PropertyValueException: not-null property references a null or transient value : model.User.ref_level
Add Comment
Please, Sign In to add comment