hibernate

how to do a JOIN FETCH in jpa criteria

混江龙づ霸主 提交于 2020-12-05 10:29:49
问题 I am trying to translate the query below to criteria api. SELECT er from ereturn er JOIN FETCH product_item pi ON pi.ereturn_id = er.id WHERE pi.status = "RECEIVED" To something like this: CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Ereturn> criteria = builder.createQuery( Ereturn.class ); Root<Ereturn> er = criteria.from(Ereturn.class); Join<Ereturn, ProductItem> productItemJoin = er.join("productItems", JoinType.LEFT); Fetch<Ereturn, ProductItem> productItemFetch = er

BeetlSQL3.0.0-M5 发布,Spring框架集成

狂风中的少年 提交于 2020-12-05 05:42:51
BeetlSQL3.0.0-M5主要对Spring,Spring Boot ,JFinal,Solon等框架进行集成,并新增 ignite,CouchBase内存数据库的支持。 M6 计划对更多的国产数据库支持, 内存和图数据库支持。以及发布BeetlSQL3的Idea 插件。 <dependency> <groupId>com.ibeetl</groupId> <artifactId>beetlsql-all</artifactId> <version>3.0.0-M5</version> </dependency> 轻松集成Spring BeetlSQL的目标是提供开发高效,维护高效,运行高效的数据库访问框架,在一个系统多个库的情况下,提供一致的编写代码方式。 传统数据库:MySQL,MariaDB,Oralce,Postgres,DB2,SQL Server,H2,SQLite,Derby,神通,达梦,华为高斯,人大金仓等 大数据:HBase,ClickHouse,Cassandar,Hive 物联网时序数据库:Machbase,TD-Engine SQL查询引擎:Drill,Presto,Druid 内存数据库:ignite,CouchBase BeetlSQL 不仅仅是简单的类似MyBatis或者是Hibernate,或者是俩这的综合

Hibernate: foreign key without entity class, only by id

核能气质少年 提交于 2020-12-05 05:14:13
问题 I have a hierarchical entity, which references it self as a parent. I need to do the mapping only via ids, not via entity instances (the reason is too complicated to explain). So I defined the entity this way: class Item { @Id private String id; @ManyToOne(targetEntity = Item.class) @JoinColumn(name = "PARENT_ID", nullable = true) private String parentId; } This seems to work fine. The foreign key constraint is created correctly in database. But when I execute the following query: SELECT i

Hibernate: foreign key without entity class, only by id

元气小坏坏 提交于 2020-12-05 05:13:48
问题 I have a hierarchical entity, which references it self as a parent. I need to do the mapping only via ids, not via entity instances (the reason is too complicated to explain). So I defined the entity this way: class Item { @Id private String id; @ManyToOne(targetEntity = Item.class) @JoinColumn(name = "PARENT_ID", nullable = true) private String parentId; } This seems to work fine. The foreign key constraint is created correctly in database. But when I execute the following query: SELECT i

Hibernate: foreign key without entity class, only by id

孤街醉人 提交于 2020-12-05 05:13:35
问题 I have a hierarchical entity, which references it self as a parent. I need to do the mapping only via ids, not via entity instances (the reason is too complicated to explain). So I defined the entity this way: class Item { @Id private String id; @ManyToOne(targetEntity = Item.class) @JoinColumn(name = "PARENT_ID", nullable = true) private String parentId; } This seems to work fine. The foreign key constraint is created correctly in database. But when I execute the following query: SELECT i

JPA---Java持久层API

浪尽此生 提交于 2020-12-05 02:26:37
JPA讲义 Java持久层API 目 录 1 JPA概述.................................................................................................................. 3 1.1 JPA是什么................................................................................................... 3 1.1.1 ORM是什么...................................................................................... 3 1.1.2 标准是什么....................................................................................... 3 1.2 JPA的实现者............................................................................................... 4 1.3 JPA的作用是什么...................

Oracle 数据库实现数据合并:merge

喜欢而已 提交于 2020-12-04 23:58:44
1、使用update进行数据更新   1)最简单的更新   update tablea a set a.price=1.00   2)带条件的数据更新   update tablea a set a.price = 2.00 where a.id='02'   3)两张表关联更新为固定值   update tablea a set a.price =3.00 where exits(select 1 from tableb b where a.id=b.id)   将a,b相同id的 a表的price 字段更新为 3.00   4)关联更新数据来源第二张表   update tablea a set a.price=(select price from tablec c ) where exits (select 1 from tablec c where a.id=c.id)   将a表price字段 更新为 id和c表id相同的数据   5)关联更新多个字段   update tablea a set ( a.price,a.type)=(select c.price,c.type from tablec c ) where exits (select 1 from tablec c where a.id=c.id)   更新a表的price 和 type 字段     6

Mapping Java boolean to Oracle Number column with JPA and Hibernate

一曲冷凌霜 提交于 2020-12-04 16:01:35
问题 I have a property created like this in my model: public class Client { private Boolean active; } My RDBMS is Oracle and the active column is of type NUMBER(1,0) . How can I use the Restrictions API to achieve the following functionality? criteria.add(Restrictions.eq("active"),object.isActive()); 回答1: Hibernate maps the Boolean Java type to Oracle NUMBER(1,0) automatically. So, you can use a Boolean value in your entity mappings, JPQL or Criteria queries and the generated SQL will use the

JPA 开发中遇到的错误

 ̄綄美尐妖づ 提交于 2020-12-04 00:43:34
JPA 开发中遇到的错误 (2011-07-13 16:56:12) 转载 ▼ 标签: 杂谈 分类: Java/J2EE 常见异常 1、异常信息:org.hibernate.hql.ast.QuerySyntaxException: person is not mapped 异常环境:查询 异常原因:查询语句中Person类没有大写 2、java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.lang.String 异常环境:查询、遍历显示 异常原因:转型出错 3、javax.persistence.NonUniqueResultException: result returns more than one elements 异常环境:查询、getSingleResult 异常原因:getSingleResult只能获取一条数据,而查询语句返回的是多条数据 4、 org.hibernate.PropertyValueException: not-null property references a null or transient value: com.sunyard.entities.Person.name 异常环境:数据插入 异常原因:JPA的Entity中一个属性定义为nullable

java编程思想(2)--一切都是对象

一曲冷凌霜 提交于 2020-12-03 14:17:30
1创建对象 String s ;创建引用,并未初始化,即引用未关联任何东西 String s2="asda"; 初始化 System.out.println(s2); System.out.println(s);//报错 用new 来初始化 String s = new String("sgjadfjaf"); 1.1如何存储 程序运行时,对象时怎么放置安排的呢?内存怎么分配的呢?  (1)寄存器   --处理器内部,外部程序感觉不到其存在 (2)堆栈   --位于RAM(随机访问存储器中),通过堆栈指针可以从处理器那里获得直接支持。堆栈指针若向下移动,则分配新的内存;若向上移动,则释放那些内存。java系统必须知道存放在堆栈上所有对象的确切生命周期,以便上下移动堆栈指针,但这一约束限制了程序的灵活性,所以最燃某些java数据存储在堆栈中--特别是对象引用,但是java对象并不存在其中。 (3)堆   一种通用的内存池(也位于RAM中),用于存放所有的java对象。堆不同与堆栈的好处是:编译器不需要知道存储的数据在堆栈里存活多长时间。因此在堆里分配时有很大的灵活性。当需要一个对象时,只要new一下,当执行到new时,会自动在堆里进行存储分配。当然,这种灵活性也要付出相应的代价;用堆进行存储分配和清理可能比用堆栈进行存储分配需要更多的时间。 (4)常量对象