hibernate

Hibernate native SQL query - how to get distinct root entities with eagerly initialized one-to-many association

流过昼夜 提交于 2021-02-11 14:27:04
问题 I have two entities Dept and Emp (real case changed and minimized). There is 1:n association between them, i.e. properties Dept.empList and Emp.dept exist with respective annotations. I want to get List<Dept> whose elements are distinct and have collection empList eagerly initialized, using native SQL query. session.createSQLQuery("select {d.*}, {e.*} from dept d join emp e on d.id = e.dept_id") .addEntity("d", Dept.class) .addJoin("e", "d.empList") //.setResultTransformer(Criteria.DISTINCT

problem creating an executable jar with maven using spring 5 and hibernate 5 => BeanDefinitionParsingException

随声附和 提交于 2021-02-11 13:48:18
问题 Update: As there is only one answer for now I try to describe it better now. In short words, my test application runs fine in eclipse and when starting with mvn exec but building a running/working executable jar package does not work for this project. Now the longer description. I'm learning Java for about 8 month and use maven to setup build projects and Eclipse as IDE for writing and debugging. Currently I am trying to make some small database projects using Spring, Hibernate and for

validator 自动化校验

醉酒当歌 提交于 2021-02-11 13:30:48
温馨提示 请收藏再看。此文篇幅太长,你短时间看不完;此文干货太多,错过太可惜。 示例代码可以关注 逸飞兮 (公众号)回复 jy 获取。 收获 讲解详细:能让你掌握使用 hibernate-validator 及类似校验工具的各种使用姿势 内容全面:可以当做知识字典来查询 what 注意:hibernate-validator 与 持久层框架 hibernate 没有什么关系,hibernate-validator 是 hibernate 组织下的一个 开源项目 。 hibernate-validator 是 JSR 380(Bean Validation 2.0) 、 JSR 303(Bean Validation 1.0) 规范的实现。 JSR 380 - Bean Validation 2.0 定义了一个实体和方法验证的元数据模型和 API。 JavaEE(改名为:Jakarta EE)中制定了 validation 规范,即:javax.validation-api(现为 jakarta.validation-api,jar 包的名字改变,包里面的包名、类名未变,因此使用方式不变)包, spring-boot-starter-web 、 spring-boot-starter-webflux 包都已引入此依赖,直接使用即可。 有点类似于 slf4j 与 logback

Spring boot JPA many to many with extra column insert and update issue

大城市里の小女人 提交于 2021-02-11 13:00:30
问题 Here is my initial question. Spring Data JPA Many to Many with extra column User and Roles Now I have the right tables created, but can't make it work for the update. Here is the code: User.java @Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String username; @OneToMany(mappedBy="user", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) private List<UserRole> roles; // getters and setters

Spring boot JPA many to many with extra column insert and update issue

耗尽温柔 提交于 2021-02-11 13:00:29
问题 Here is my initial question. Spring Data JPA Many to Many with extra column User and Roles Now I have the right tables created, but can't make it work for the update. Here is the code: User.java @Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String username; @OneToMany(mappedBy="user", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) private List<UserRole> roles; // getters and setters

Spring boot JPA many to many with extra column insert and update issue

吃可爱长大的小学妹 提交于 2021-02-11 12:59:24
问题 Here is my initial question. Spring Data JPA Many to Many with extra column User and Roles Now I have the right tables created, but can't make it work for the update. Here is the code: User.java @Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String username; @OneToMany(mappedBy="user", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) private List<UserRole> roles; // getters and setters

H2 schema still generated when spring.jpa.generate-ddl=false

大城市里の小女人 提交于 2021-02-11 12:33:32
问题 I am using Spring Boot 2.1.3 with an H2 in memory database for testing. When I run my tests, the schema gets generated even when I specify the following property. spring.jpa.generate-ddl=false It seems that because Spring Boot defaults the following property when using H2 spring.jpa.hibernate.ddl-auto=create-drop That this takes precedence over spring.jpa.generate-ddl=false Is this a bug? 来源: https://stackoverflow.com/questions/55575505/h2-schema-still-generated-when-spring-jpa-generate-ddl

Skip NonUniqueDiscoveredSqlAliasException when two table has same column names

蓝咒 提交于 2021-02-11 12:29:29
问题 My existing application is using HibernateDAOSupport and hibernateTemplate with version 3.6.10. When I have a native query like below then it works fine with current system. select a.name, b.name from a inner join b on a.bid=b.id Now I am upgrading my application to JPA so it throws me error : NonUniqueDiscoveredSqlAliasException I can fix this error by changing query to below one: select a.name as aname, b.name from a inner join b on a.bid=b.id But the problem is my application is huge and

Spring MVC----Validation(数据校验)

这一生的挚爱 提交于 2021-02-11 11:40:50
简化服务器验证 JSR-303 简介 JSR-303 是 JavaEE 6 中的一项子规范,叫做 Bean Validation,官方参考实现是 Hibernate Validator。 此实现与 Hibernate ORM 没有任何关系。JSR-303 用于对 Java Bean 中的字段的值进行验证。 Spring MVC 3.x 之中也大力支持 JSR-303,可以在控制器中使用注解的方式对表单提交的数据方便地验证。 Spring 4.0 开始支持 Bean Validation 功能。 JSR-303 基本的校验规则 空检查 @Null 验证对象是否为 null @NotNull 验证对象是否不为 null , 无法查检长度为 0 的字符串 @NotBlank 检查约束字符串是不是 Null 还有被 Trim 的长度是否大于 0,只对字符串,且会去掉前后空格 @NotEmpty 检查约束元素是否为 NULL 或者是 EMPTY 布尔检查 @AssertTrue 验证 Boolean 对象是否为 true @AssertFalse 验证 Boolean 对象是否为 false 长度检查 @Size(min=, max=) 验证对象( Array , Collection , Map , String )长度是否在给定的范围之内 @Length(min=, max=)

SEVERE: Exception looking up UserDatabase under key UserDatabase javax.naming.NameNotFoundException: Name [UserDatabase] is not bound in this Context

孤者浪人 提交于 2021-02-11 09:52:20
问题 im using TOMCAT 9 and latest hibernat jars with java 1.8 i create simple user in mysql and 1 table db called foo1 in my webapp in tomcat i configured based on examples online : workspace\HibernateApp\src\hibernate.cfg.xml: <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="show_sql">true<