Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE users (
- ID INT AUTO_INCREMENT,
- FIRSTNAME VARCHAR(100) NOT NULL,
- LASTNAME VARCHAR(100) NOT NULL,
- AGE INT NOT NULL,
- ID_ROLE INT NOT NULL,
- ID_LEVEL INT NOT NULL,
- PRIMARY KEY (ID)
- );
- CREATE TABLE roles (
- ID INT AUTO_INCREMENT,
- ROLE VARCHAR(100) NOT NULL,
- );
- CREATE TABLE levels (
- ID INT AUTO_INCREMENT,
- LEVEL VARCHAR(100) NOT NULL,
- );
- public class User {
- int id, age;
- private String firstname, lastname;
- private Role ref_role;
- private Level ref_level;
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public String getFirstName() {
- return firstname;
- }
- public void setFirstName(String firstname) {
- this.firstname= firstname;
- }
- public String getLastName() {
- return lastname;
- }
- public void setLastName(String lastname) {
- this.lastname= lastname;
- }
- public Ruolo getRef_role() {
- return ref_role;
- }
- public void setRef_role(Role ref_role) {
- this.ref_ruolo = ref_ruolo;
- }
- public Livello getRef_level() {
- return ref_level;
- }
- public void setRef_level(Level ref_level) {
- this.ref_level= ref_level;
- }
- public User() {}
- }
- public class Role {
- private int id;
- private String role;
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getRole() {
- return role;
- }
- public void setRole(String role) {
- this.role = role;
- }
- public Role() {
- }
- }
- public class Level {
- private int id;
- private String level;
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getLevel() {
- return level;
- }
- public void setLevel(String level) {
- this.level = level;
- }
- public Level() {}
- }
- <hibernate-configuration>
- <session-factory>
- <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="connection.url">jdbc:mysql://localhost:3306/mydatabase</property>
- <property name="connection.username">root</property>
- <property name="connection.password"></property>
- <property name="hibernate.c3p0.min_size">5</property>
- <property name="hibernate.c3p0.max_size">20</property>
- <property name="hibernate.c3p0.timeout">300</property>
- <property name="hibernate.c3p0.max_statements">50</property>
- <property name="hibernate.c3p0.idle_test_period">3000</property>
- <mapping resource="user.hbm.xml"/>
- <mapping resource="role.hbm.xml"/>
- <mapping resource="level.hbm.xml"/>
- </session-factory>
- </hibernate-configuration>
- <hibernate-mapping>
- <class name="User" table="users">
- <id name="id" column="ID" type="integer">
- <generator class="native"/>
- </id>
- <property name="firstname" column="FIRSTNAME" type="string"/>
- <property name="lastname" column="LASTNAME" type="string"/>
- <property name="age" column="AGE" type="integer"/>
- <many-to-one name="ref_role" class="Role" column="ID_ROLE" not-null="true"/>
- <many-to-one name="ref_level" class="Level" column="ID_LEVEL" not-null="true"/>
- </class>
- </hibernate-mapping>
- <hibernate-mapping>
- <class name="Role" table="roles">
- <id name="id" column="ID" type="integer">
- <generator class="native"/>
- </id>
- <property name="role" column="ROLE" type="string"/>
- </class>
- </hibernate-mapping>
- <hibernate-mapping>
- <class name="Level" table="levels">
- <id name="id" column="ID" type="integer">
- <generator class="native"/>
- </id>
- <property name="level" column="LEVEL" type="string"/>
- </class>
- </hibernate-mapping>
- org.hibernate.PropertyValueException: not-null property references a null or transient value : model.User.ref_level
Add Comment
Please, Sign In to add comment