Tag: hibernate

如何在hibernate实体中更改列名?

我有以下hibernate实体: @Table(name=”tbl_template”) @Entity @Audited public class StatementTemplate { private Long id; @Column(name = “template_name”) private String templateName; … } 我将列名从template_name更改为stmt_name @Column(name = “stmt_name”) private String templateName; 事实certificate,而不是更改列名hibernate添加了另一个名为stmt_name的列,现在我有了template_name以及stmt_name 我有以下hibernate属性设置 update 如何将列从template_name更改为stmt_name?

如何使用hibernate查询连接表?

我在Oracle SQL Developer中创建了三个表 1.Test_Employee2 2.Test_Project2 3.Employee_Project2 。 表Employee_Project2是连接表,因为Test_Project2和Employee_Project2之间的关系是Many-To-Many 。 在hibernate中,我分别为Test_Project2和Employee_Project2表创建了两个hibernate类TestEmployee和TestProject , 而Employee_Project2表在TestProject hibernate类中定义如下: @ManyToMany(cascade = CascadeType.ALL) @JoinTable(name = “Employee_Project2”, joinColumns = @JoinColumn(name = “proj_id”), inverseJoinColumns = @JoinColumn(name = “emp_id”)) private Set employeesList; 我用一些记录填充了表Test_Project2和Employee_Project2 ,并且连接表Employee_Project2自动填充了一些记录。 现在我面临的问题是,我想在使用hiberante的连接表Employee_Project2上使用一个简单的select语句,如下所示: String hql = “FROM Employee_Project2”; Query query = session.createQuery(hql); List results = query.list(); for (Object row : results) { //what […]

关注hibernate查询的问题

我正在处理使用hibernate向下转换query.uniqueResult()的问题。 我有2个类: – UserBean – UserLogin 在第一个中,我有所有表字段的映射以及处理数据的所有方法。 相反,第二个仅表示将存储在用户会话中的一些用户数据。 在我的登录方法的某一点,我执行查询,我得到1行(我已经检查过,如果查询确实返回了一些结果)。 关键是我不能将Object类型(即query.uniqueResult()类型)向下转换为UserLogin类型。 有人知道哪个可能是问题吗? 非常感谢! 这是登录方法: public UserLogin login(String email, String password){ Session session = iniHibernate(); UserLogin userLogin = null; try{ session.beginTransaction(); Query query = session.createQuery(“select email, name from ” + “UserBean u where u.email = :user_email and ” + “u.password = :user_password”); query.setString(“user_email”, email); query.setString(“user_password”,password); userLogin = […]

传播.REQUIRES_NEW似乎不起作用

使用Spring(MVC,Batch和persistence)我定义了以下接口: public interface JobStatusService { @Transactional(readOnly = false) @Modifying JobStatus save(JobStatus status); @Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW) Optional get(ResultsIdentifier identifier); } 请注意REQUIRES_NEW因为它是在破碎的方法上。 该接口实现于: @Override public JobStatus save(JobStatus status) { if (status.getUserId() == null) { status.setUserId(userService.getCurrentUser()); } status.setLastUpdateTime(new Date()); return repository.save(status); } @Override public Optional get(ResultsIdentifier identifier) { return repository.findByJobIdentifier(identifier); } 其中repository是JPA存储库,其中包含以下内容: public interface JobStatusRepository […]

spring-hibernate花费更多时间的原因是什么?

目前,我正在Spring和hibernate上开展一个项目。我来到这里。 获取记录并在JSP中显示这些记录需要更多时间。 我把时间戳保存在各处,看看它花了更多的时间: Time @ HomeController[start] : 2014-07-09 18:58:52.621 **Time @ userService[start] : 2014-07-09 18:58:52.622** **Time @ UserDao[start] : 2014-07-09 18:58:57.678** Time before executing Query : 2014-07-09 18:58:57.678 Time After executing Query : 2014-07-09 18:58:59.272 Time @ UserDao[end] : 2014-07-09 18:58:59.272 Time @ userService[End] : 2014-07-09 18:59:00.068 Time @ HomeController[end] : 2014-07-09 18:59:00.068 Time stamp […]

Struts 2:带点或逗号的双精度值

我不能用点(例2.2)插入双值的问题,但是我可以用逗号插入它们(例如:2,2)。 但是当我想使用(JSP和Ajax)编辑它们时,即使我用逗号存储它们,它们也会出现(点),所以我必须编辑所有值! 场景如下:我想在我的应用程序(hibernate和struts2)中编辑一些double值,我将值从action传递给JSP: private Service Service; private Vehicule v; private Map map= new HashMap(); public String query() { Service = new ServiceImpl(); v = new Vehicule(); v= Service.getVehiculeByImmat(field1); map.put(“date”, v.getdate().toString()); map.put(“kilometrage”, v.getKilometrage()); return “success”; } 然后我在我的JSP中显示它们: $(document).ready(function(){ $(‘#field1’).change(function(){ var selectedValue = $(‘#field1’).val(); if ($.trim(selectedValue).length > 0) { alert(selectedValue); $.ajax( { type: ‘POST’, url : “”, […]

@OneToMany删除子项

我有两个这样的实体: public class Client { … @OneToMany(mappedBy = “client”, cascade = { CascadeType.DETACH, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.REMOVE },orphanRemoval = true, fetch=FetchType.EAGER) @Fetch(value = FetchMode.SUBSELECT) @Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE_ORPHAN }) private List companyContracts; … } 公司合同: public class CompanyContract { … @ManyToOne @JoinColumn(name = “IDCLIENT”) private Client client; … } 我想删除像这样的companyContract: client.getCompanyContracts().remove(companyContract) client = clientService.updateClient(client); 但删除过程没有发生 我究竟做错了什么 ? […]

Hibernate java.lang.OutOfMemoryError:Java堆空间

我有一个在Tomcat 7上运行的Java Web应用程序 – jdk1.7 此应用程序使用Spring 4.1.5.RELEASE和Hibernate 4.2.2.Final 我的问题是建筑部分工厂的堆空间的OutOfMemoryException 这是我打开SessionFactory的静态方法 public class GenericDAO { public static SessionFactory sessionFactory = null; public static ServiceRegistry serviceRegistry = null; Transaction tx = null; public static SessionFactory createSessionFactory() { Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new ServiceRegistryBuilder().applySettings( configuration.getProperties()). buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); return sessionFactory; } } 这是DAO的一个例子 […]

如何通过hibernate访问pl / sql proc中的out参数

我有一个带有以下签名的pl / sql过程 PROCEDURE pr_log_process_started ( p_process_id IN log_process_status.process_id%TYPE, p_run_id IN OUT log_process_status.run_id%TYPE); 如何通过Hibernate调用此proc并在调用后访问第二个参数的值?

LazyInitializationException,同时使用TestNG对Spring中使用的Hibernate实体类进行unit testing

在我的Spring配置中,我已经要求会话在我的视图中保持打开状态: 但是,这个bean似乎并不认为我的TestNGunit testing是一种观点。 ;-)那没关系,但是unit testing是否有类似的bean,以便在unit testing时避免可怕的LazyInitializationException? 到目前为止,我的一半unit testing因此而死亡。 我的unit testing通常如下所示: @ContextConfiguration({“/applicationContext.xml”, “/applicationContext-test.xml”}) public class EntityUnitTest extends AbstractTransactionalTestNGSpringContextTests { @BeforeClass protected void setUp() throws Exception { mockEntity = myEntityService.read(1); } /* tests */ @Test public void LazyOneToManySet() { Set entities = mockEntity.getSomeEntitySet(); Assert.assertTrue(entities.size() > 0); // This generates a LazyInitializationException } } 我已经尝试将setUp()更改为: private SessionFactory sessionFactory […]