【发布时间】:2017-10-30 13:04:32
【问题描述】:
我有一个代理类和一个扩展代理的用户类。 我想将持久代理强制转换为用户并使用相同的 id、名称和名字来持久化用户。我不打算在 Agent 表中插入另一行。我该怎么做?
这是我的课程。
@Entity
@Table(name = "agent")
@Inheritance(strategy = InheritanceType.JOINED)
public class Agent {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected Integer id;
@Column(name = "fistname", nullable = false)
protected String fistname;
@Column(name = "name", nullable = false)
protected String name;
}
@Entity
@Table(name="user")
public User extends Agent{
@Column(name = "login", nullable = false, unique = true)
public String login;
@Column(name = "password", nullable = false)
public String password;
我愿意这样做
Agent agent=agentService.findOne(1);
User user = new User(agent);
user.setLogin("login");
...
user=userService.saveAndFlush(user);
ok = user.getId() == agent.getId();
总之,我想在需要时将代理授予用户。
【问题讨论】:
-
你的问题不清楚,具体点