cclafuente
Sep 28th, 2007, 06:41 AM
I'm using spring and hibernate annotations, i try all the next sentences to set a role to a user:
1. <form:select path="role" items="${roles}" />
2. <form:select path="role.id" items="${roles}" itemValue="id" itemLabel="authority"/>
<form:select path="role" items="${roles}" itemValue="id" itemLabel="authority"/>
<form:select path="role">
<form:options items="${rolesLV}" itemValue="id" itemLabel="authority"/>
</form:select>
<form:select path="role.id">
<form:options items="${roles}" itemValue="id" itemLabel="authority"/>
</form:select>
1. I think that the correct was the first sentence, the most simple, but in this case, the exception was something like i was trying to convert a string in a object Role, and it was no correct.
2. In the second sentence, spring tried to change in the table Role, the id, and in the table user too, but i don't want to change nothing in the table role, i only want to change in the table users, the id of his role, the exception was:
identifier of an instance of com....Role was altered from 1 to 2; nested exception is org.hibernate.HibernateException...
In hibernate annotations, here is my code:
Role:
@Entity
@Table(name="roles")
public class Role {...
@Id @Column(name="role_id")
public String getId() {
return id;
}
.....
User:
@Entity...
.....
@ManyToOne
@JoinColumn(name="role_id")
public Role getRole() {
return role;
}
Why is trying to change the role.id in any other place that in the user.role.id?
1. <form:select path="role" items="${roles}" />
2. <form:select path="role.id" items="${roles}" itemValue="id" itemLabel="authority"/>
<form:select path="role" items="${roles}" itemValue="id" itemLabel="authority"/>
<form:select path="role">
<form:options items="${rolesLV}" itemValue="id" itemLabel="authority"/>
</form:select>
<form:select path="role.id">
<form:options items="${roles}" itemValue="id" itemLabel="authority"/>
</form:select>
1. I think that the correct was the first sentence, the most simple, but in this case, the exception was something like i was trying to convert a string in a object Role, and it was no correct.
2. In the second sentence, spring tried to change in the table Role, the id, and in the table user too, but i don't want to change nothing in the table role, i only want to change in the table users, the id of his role, the exception was:
identifier of an instance of com....Role was altered from 1 to 2; nested exception is org.hibernate.HibernateException...
In hibernate annotations, here is my code:
Role:
@Entity
@Table(name="roles")
public class Role {...
@Id @Column(name="role_id")
public String getId() {
return id;
}
.....
User:
@Entity...
.....
@ManyToOne
@JoinColumn(name="role_id")
public Role getRole() {
return role;
}
Why is trying to change the role.id in any other place that in the user.role.id?