Database tables:
CREATE TABLE user ( uid serial NOT NULL, user_id character varying(10) NOT NULL, password character varying(50), screen_name character varying(100) NOT NULL, auth_type integer NOT NULL, active_flag boolean NOT NULL, delete_flag boolean NOT NULL, created_by integer NOT NULL, created_on timestamp with time zone NOT NULL, modified_by integer NOT NULL, modified_on timestamp with time zone NOT NULL, CONSTRAINT user_pkey PRIMARY KEY (uid ), CONSTRAINT user_user_id_key UNIQUE (user_id ) )
CREATE TABLE PREFERENCES ( UID serial NOT NULL, USER_ID integer NOT NULL, Theme character varying(50), Template character varying(50), CREATED_BY integer NOT NULL, CREATED_ON timestamp with time zone NOT NULL, MODIFIED_BY integer NOT NULL, MODIFIED_ON timestamp with time zone NOT NULL, CONSTRAINT PREFERENCES_PKEY PRIMARY KEY (USER_ID), CONSTRAINT PREFERENCES_FKEY FOREIGN KEY (USER_ID) REFERENCES USER (UID) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION
);
I our application we are using JPA annotations
hibernate mapping using annotations
Due to security reason i cant able to upload entire file
user.java file is like this
I have defined properties along with the property for preferences
private UserPreferences userPreferences;
I am doing mapping as
line 1: @OneToOne(fetch = FetchType.EAGER,cascade = CascadeType.ALL)
line2: @JoinColumn(name="UID",referencedColumnName="USER_ID")
preferences.java file
This is my userpreference file
@Entity
@Table(name="USER_PREFERENCES")
public class UserPreferences {
private int uid;
private String userId;
private String theme;
private String template;
public UserPreferences(int uid, String userId, String theme, String template, RecordDetails recordDetails) {
super();
this.uid = uid;
this.userId = userId;
this.theme = theme;
this.template = template;
}
@Id
@Column(name="UID",updatable=false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
@Column(name="USER_ID", updatable=false, unique=true)
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
@Column(name="THEME")
public String getTheme() {
return theme;
}
public void setTheme(String theme) {
this.theme = theme;
}
@Column(name="TEMPLATE")
public String getTemplate() {
return template;
}
public void setTemplate(String template) {
this.template = template;
}
}
all the properties as per the database table i have given in it.
I am having users list and i want to assign a preference for each user so i took one to one mapping
When there is no row for a preference table i can able to see the list of users and add the preference for any user. once after coming back and getting the userlist i am seeing an error as
No default constructor for entity: UserPreferences
Can you please help me why i am getting this only after adding a row in preference how can i solve it.
Here at the below line i am getting an exception
Criteria criteria = session.createCriteria(User.class); usersList = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
Thanks in advance