hibernate

Hibernate delete from onetomany

被刻印的时光 ゝ 提交于 2021-01-27 05:23:29
问题 I have two tables with OneToMany relation class ServiceProvider { ... @OneToMany(fetch=FetchType.EAGER,mappedBy="serviceProvider", cascade={CascadeType.ALL,CascadeType.REMOVE},orphanRemoval = true) @OnDelete(action=OnDeleteAction.CASCADE) private List serviceCenters; ... } class ServiceCenterDetails { ... //bi-directional many-to-one association to ServiceProviderDomainMap @ManyToOne @JoinColumn(name="SERVICE_PROVIDER_ID") private ServiceProvider serviceProvider; ... } I am trying to delete

Hibernate select elements of collection with a given property

风格不统一 提交于 2021-01-27 05:13:27
问题 Entity Project has a collection property contributors mapped with a @OneToMany relationship to entity User @Entity @Table( name = "projects" ) public class Project { ... @OneToMany @JoinTable(name = "project_contributors") private List<User> contributors = new ArrayList<User>(); ... } I then need to check if contributors already has a user with id contributorId before adding it. I am trying with HQL query, but I am clearly quite innept. What I am trying: Query query = session.createQuery(

Best way to truncate all tables with hibernate?

。_饼干妹妹 提交于 2021-01-27 04:53:07
问题 I would like to truncate all my database tables between one integration test to another. What is the best way to do this using hibernate? Currently I'm doing this: public void cleanDatabase() { doWithSession(new Action1<Session>() { @Override public void doSomething(Session session) { SQLQuery query = session.createSQLQuery("truncate table stuff"); // todo - generify this to all tables query.executeUpdate(); } }); (doWithSession is a small wrapper that creates and closes a session). I could

No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2

青春壹個敷衍的年華 提交于 2021-01-27 04:49:38
问题 I am defining two EntityManager beans for two different databases. Each EntityManager bean refers to a unique, respective <persistence-unit/> defined in persistence.xml . The same code and config worked fine with Spring 2.x. When I upgrade to Spring 3, I see the following exception while deploying the app in the server: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean

@OneToMany with @JoinTable error

寵の児 提交于 2021-01-27 04:21:33
问题 I'm trying to understand **@OneToMany** with **@JoinTable** for such scenerio I'm using JPA 2.1, Hibernate 5.0.4 and Oracle 11 XE. When i call userDao.save(user) (code below) i've got java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (HIBERNATE.USER2ORDER_PK) violated What am I doing wrong? Could someone help me understand? DDL: DROP TABLE HIBERNATE.T_USER2ORDERS; DROP TABLE HIBERNATE.T_ORDERS; DROP TABLE HIBERNATE.T_USERS; DROP SEQUENCE HIBERNATE.USERS_SEQ; DROP

org.hibernate.type.TextType and Oracle

亡梦爱人 提交于 2021-01-27 04:08:54
问题 We use Hibernate as a JPA provider and we have a class with a large object field marked with @Lob @Type( type = "org.hibernate.type.TextType" ) private String someString; The column is created as SOMESTRING LONG() This works flawlessly with PostgreSQL and MySQL. With Oracle when persisting the object entityManager.persist( object ); we get an org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update exception. Removing the @Type( type = "org.hibernate.type.TextType" )

SessionFactory from EntityManager throws exception

牧云@^-^@ 提交于 2021-01-27 03:53:05
问题 I'm trying to get the Hibernate's SessionFactory from JPA's EntityManager with the following lines: @PersistenceContext EntityManager manager; public SessionFactory getSessionFactory(){ sessionFactory = manager.unwrap(SessionFactory.class); } But it throws this exception: org.springframework.orm.jpa.JpaSystemException: Hibernate cannot unwrap interface org.hibernate.SessionFactory; nested exception is javax.persistence.PersistenceException: Hibernate cannot unwrap interface org.hibernate

SessionFactory from EntityManager throws exception

戏子无情 提交于 2021-01-27 03:52:27
问题 I'm trying to get the Hibernate's SessionFactory from JPA's EntityManager with the following lines: @PersistenceContext EntityManager manager; public SessionFactory getSessionFactory(){ sessionFactory = manager.unwrap(SessionFactory.class); } But it throws this exception: org.springframework.orm.jpa.JpaSystemException: Hibernate cannot unwrap interface org.hibernate.SessionFactory; nested exception is javax.persistence.PersistenceException: Hibernate cannot unwrap interface org.hibernate

How to do a simple table join in Grails

时光毁灭记忆、已成空白 提交于 2021-01-27 03:50:41
问题 I'm kind of new to grails and I'm having a lot of trouble with joining two existing tables through domain objects that have been created off of those tables. Does anyone know how to do this in grails? Here are what the tables look like and an example of how I need the joined table to look. Thanks in advance for the help. Table1{ field1table1 } Table2{ field1table2 field2table2 } I need to join these 2 tables where field1table1 = field1table2 and the resulting table join I need to look like

微服务接口校验

假装没事ソ 提交于 2021-01-26 18:26:40
微服务接口校验 三丰 soft张三丰 API 设计方案 Http的请求分为URL约定规则、请求参数规则 URL规则: http://{server}/{product}/{version}/{logic}/{method}?{query_string }  1.server: 为具体的服务域名 2.product: 为应用工程名 3.version: 为具体版本号, 便于将来的功能扩展, 可以暂定为 v1, v2 4.logic: 为具体业务逻辑的初步划分, 比如后端管理方法, app端的请求方法 5.method: 具体业务的方法 具体的请求参数, 由指定的method方法决定, 全都作为HTTP GET/POST的参数列表。 如果响应结果失败,则返回如下结果: {       data : { // 请求数据,对象或数组均可       },       msg : "Internal Server Error", // 请求状态描述,调试用       success : 0,       code : 5001, // 业务自定义状态码       extra : {       }     } } 错误码 API 在设计的时候,最好不要将业务错误码与HTTP状态码的绑定,重新定义一套业务错误码,来区分HTTP 的状态码。    状态码的定义也最好有一套规范,类似于HTTP