hibernate

框架修炼之ssm-Mybatis学习笔记一

会有一股神秘感。 提交于 2020-08-08 18:06:57
早期ssh框架:spring struts2 hibernate. 目前使用ssm:spring(service) springMVC(servlet) mybatis(jdbc DbUtil) JDBC回顾 1 准备数据库tb_user @Test public void test ( ) throws Exception { // 1 加载驱动 Connection connection = null ; PreparedStatement Statement = null ; ResultSet resultSet = null ; try { Class . forName ( "com.mysql.jdbc.Driver" ) ; // 2 获取连接 connection = DriverManager . getConnection ( "jdbc:mysql://localhost:3306/mybatis" , "root" , "1234" ) ; // 3 获取preparestatement String sql = "select * from tb_user where id = ?" ; Statement = connection . prepareStatement ( sql ) ; // 4 设置参数 Statement . setLong (

Mark non db fields @Transient vs extent JPA Entity?

情到浓时终转凉″ 提交于 2020-08-08 17:16:27
问题 We have a JPA Entity . Once the entity is persisted in db, some fields of this entity(db columns) along with some other data (which is not part of this entity) has to be stored in a JCR object-store. Should I create one single Entity(JPA) for both DB and JCR and just add JCR fields in Entity and mark them @Transient? or Should I use inheritance or composition(using JPA Entity) and create a new JCR specific object? Basically, should JPA entities be strictly used for DB or is @Transient in this

一言难尽,Jpa这个功能差点让我丢了工作

試著忘記壹切 提交于 2020-08-08 09:03:08
故事背景 前阵子,有位朋友在微信上问我数据被删了能不能恢复,我问了下原因,居然是因为一个配置项惹的祸。 故事细节 在 Spring Boot 中使用 jpa 来操作数据库,jpa 就不做详细的介绍了,相信大家都有所了解或者也用过。 在 jpa 中有一个配置项,可以让程序在启动的时候自动初始化表结构或者更新表结构的功能。听上去很不错,非常实用。 其实这是一个非常危险的功能,个人觉得不应该提供这种功能,只要留了口子就有可能会出问题。 这个配置就是: spring.jpa.hibernate.ddl-auto create( 危险系数 2 颗星 ) 应用启动的时候,如果数据库中没有对应的表,就会自动根据实体类的结构创建一个表结构。如果表已经存在了就会将表中的数据清空。 create-drop( 危险系数 3 颗星 ) 应用启动的时候,如果数据库中没有对应的表,就会自动根据实体类的结构创建一个表结构。如果表已经存在了就会将表中的数据清空。 程序停止的时候会将数据库中所有表删除掉。 update( 危险系数 1 颗星 ) 应用启动的时候,如果数据库中没有对应的表,就会自动根据实体类的结构创建一个表结构。如果表已经存在了就会判断有没有新增字段或者修改长度之类的,如果有则会更新表结构,不会影响数据。 validate( 危险系数 0 颗星 ) validate 不会更新和删除表或者数据

Springboot快速上手- 第二篇 helloWord走起

孤者浪人 提交于 2020-08-07 19:32:17
1 基础工程创建 1:创建一个maven工程 2:加入parent <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> </parent> 3:加入启动依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> 4:设置properties <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <start-class>com.cc.Application</start-class> </properties> 5:配置springboot 插件 <build> <finalName>springbootstudy</finalName> <plugins> <plugin> <groupId>org

β冲刺总结

邮差的信 提交于 2020-08-07 10:10:22
项目预期计划 完成用户端、商家端,基本实现预约点餐、发送评论、购物车、查询订单、评论、使用红包等功能 现实进展 用户端基本完成,但是缺少商家端和管理员端 过程体会 041701602: 可以说是比较在预料之内的结果吧,β冲刺我们的准备并没有非常充分,整个项目几乎完全重启,但是要完成之前预计两次冲刺才能完成的内容时间上还是不够有余裕。 这次我们冲刺开始的时间比较晚,是因为之前安排了一段组员学习新技术的时间,可以说还是有点怠慢了吧,如果还能把这段时间继续提前的话我们后面还能有更多的时间补齐我们需要完成的内容。 和新组员的交涉过程中收获很大,对于一些以前掌握的不太好的技术有了新的理解,学习上还是要多避免闭门造车。 221701111: 终于结束了,但说是结束,从项目完成度来说,远远达不到结束,与预期结果差得有点远,从alpha其实也大致看得出,我们小组除了交换进来的成员基础比较好,其他也都一般般,我也是,但我从不为此气馁,不会就去学,去做,经过这次项目的开发过程,我觉得我整个人都不一样了,有压力,有动力。 在alpha冲刺之中我本来是在后端组的,也跟上了后端的脚本,代码也都有在写,做出了自己的贡献,我很欣慰自己能做下去,但前端组的情况却不容乐观,一点进度都没有,相当于啥都没做,还是我们后端组最后去前端组帮补了点,于是在这次beta冲刺中,我觉得我得去前端组,让新来的成员去后端组

JPA Hibernate Dynamic entity mapping & persistence at runtime

浪子不回头ぞ 提交于 2020-08-07 09:49:29
问题 Basically we have a spring boot application that requires that the user can define his/her own set of fields and that these fields should be persisted in their own class/table through JPA/Hibernate at runtime. These classes will be generated dynamically through bytebuddy. All that should be done dynamically without having to restart the application. The Hibernate Dynamic mapping is not an option, since we will be creating new classes entirely and re-map them. I have also considered an EAV

Hibernate基础知识

不羁的心 提交于 2020-08-07 08:40:42
1、Hibernate操作数据库的步骤 读取hibernate全局配置-->使用hibernate全局配置创建sessionFactory-->使用sessionFactory对象获取session-->开启事务-->使用session对象进行数据库操作(增删改查)-->提交事务-->关闭session 以下给出最基本的写法示例: Configuration configuration = new Configuration(); Configuration configure = configuration.configure( "hibernate.cfg.xml" ); SessionFactory sessionFactory = configuration.buildSessionFactory(); session = sessionFactory.openSession(); public void insertOne() { transaction .begin(); Department department = new Department(); department.setDeptName( " 技 术 部 " ); department.setDeptNo( "123" ); department.setDeptAddr( " 北京市 " );

Hibernate and tables with same data/columns but with different table names

可紊 提交于 2020-08-07 07:11:27
问题 The database I am working with has many tables with the same columns but with (obviously) different table names (I didn't design it). For example (these are database table names): company1Data company2Data company3Data etc. Would it be possible to map these to one Java class entity with JPA and hibernate? The name of the class would be Data , and then pass in for example company1 somewhere when using it so that object would use the company1Data table? Or is it better to just use normal, plain

Hibernate and tables with same data/columns but with different table names

我们两清 提交于 2020-08-07 07:10:20
问题 The database I am working with has many tables with the same columns but with (obviously) different table names (I didn't design it). For example (these are database table names): company1Data company2Data company3Data etc. Would it be possible to map these to one Java class entity with JPA and hibernate? The name of the class would be Data , and then pass in for example company1 somewhere when using it so that object would use the company1Data table? Or is it better to just use normal, plain