English 中文(简体)
使用休眠来传播现有实体
原标题:Populating an existing entity using hibernate

其同样的问题有: 将现有实体仅使用Nhibertate 进行正常的休眠,而不是Nhebertnate,这个问题也没有完全回答海事组织。

总而言之,能否(在休眠中)由一个以前附属的实体填补/容纳一个新实体?

daoService.getEntityManager().find(Student.class, 123L); 
Student student = new Student(123) // Creating a new student

daoService.fill(student);

结果应该是,学生案例的准确价值将与实体经理发现的确切价值相同。

I can t use merge, as it returns a new instance (instead of filling the given instance) and I can t use load() if the ID belongs to an already attached entity. I want the code to be generic to every entity, so its not practical to just set the values manually. I d rather not use refelection in this context because of all the potential pitfalls (Lazy initialization, inheritance, get methods with no corresponding set methods and vice versa, etc.)

我正在研究一个传统系统,该系统既使用联合行动计划实体,也使用非实体(与联合开发银行合作),这可以解决我的一些重大问题。

提前感谢您的帮助!

问题回答

语法不完全准确,因为我写了我的头顶

Student student = new Student();

metadata = factory.getClassMetaData(Student.class);

metadata.getIdproperty();
// copy id

for(Property prop in metadata.getPropertyClosureIterator)
{
    prop.setValue(student, prop.getValue(managedStudent));
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签