dao

JPA Self Join using JoinTable

主宰稳场 提交于 2019-11-29 17:35:36
I have 1 entity call Item in which I want to be able to link parent items to children. to use a join table to create a parent/child relationship. I haven't been able to get any good documentation on. So if anyone has any thoughts I'm all ears. Here is what I have... which works most of the time. public class Item implements java.io.Serializable { @Id private Long id; @ManyToOne(optional = true, fetch = FetchType.LAZY) @JoinTable(name = "ITEMTOITEM", joinColumns = { @JoinColumn(name = "ITEMID") }, inverseJoinColumns = { @JoinColumn(name = "PARENTITEMID") } ) private Item parent; @OneToMany

service

末鹿安然 提交于 2019-11-29 16:19:19
1Dao和service对应 一般情况下,Hibernate DAO只操作一个POJO对象,因此一个DAO对应一个POJO对象。 Service层是为了处理包含多个POJO对象(即对多个表的数据操作)时,进行事务管理(声明式事务管理)。Service层(其接口的实现类)被注入多个DAO对象,以完成其数据操作。 2 Service之有无 两种构建业务层的模式: 模式1是Service + DAO,即DAO中只做CRUD及类似的简单操作(称之为功能点,不包含业务逻辑),Service中通过调用一个或多个DAO中的功能点来组合成为业务逻辑.Service的数量应该由功能模块来决定。 在这种模型中业务逻辑是放在Service中的,事务的边界也应该在Service中控制. 当然,直接在Service中控制事务会引入非业务逻辑的代码,幸好Spring的AOP可以解决这个问题,这也是引入Spring的原因之一. 如果说到缺点,就在于对某些对象的操作就是简单的CRUD,Service层显得累赘. 模式2是Service + BO, 而BO = DAO + 业务方法, 在原先DAO的基础上添加业务方法,形成BO对象。需要注意的是BO中的业务方法往往是针对一个实体对象的,如果需要跨越多个实体对象,则方法应该放在Service中。 举例来说,一个简单的银行帐户管理系统,创建帐户这个BO对象

Struts2,Spring,Hibernate框架的优缺点

旧巷老猫 提交于 2019-11-29 14:55:59
Struts2,Spring,Hibernate框架的优缺点 分类: SSH框架整合 2010-05-26 21:27 5432人阅读 评论(0) 收藏 举报 strutsspringhibernate框架daomvc 开源是3个框架共有的优点 Struts2框架(MVC框架)的优点如下: 1) 实现了MVC模式,层次结构清晰,使程序员只需关注业务逻辑的实现; 2) 丰富的标签库,大大提高了开发的效率; 3) Struts2提供丰富的拦截器实现 3) 通过配置文件,就可以掌握整个系统各个部分之间的关系; 4) 异常处理机制,只需在配置文件中配置异常的映射,即可对异常做相应的处理; Spring框架的优点如下: 1) 无入侵性(在业务逻辑代码中感觉不到Spring框架的存在); 2) 各个组件之间的耦合极为松散; 3) 无需程序员自己实现singleton模式; 4) 通过AOP,可以实现事务管理和日志管理; 5) 整合其他的框架,如:struts框架和hibernate框架; Hibernate框架(ORM框架)的优点如下: 1) 对象/关系数据库映射(ORM), 使用时只需操纵对象,使开发更加面向对象化; 2) 无入侵性; 3) 简洁的HQL语句,减少了JDBC与SQL操作数据库的代码量; 4) 移植性好; 缺点如下: 1) 对批量更新,删除的支持不好; 什么是SSH2框架

记录下之前所总结的spirngmvc数据库的一些杂乱知识点

佐手、 提交于 2019-11-29 14:17:52
(!!在springmvc控制器层,查询到的学生信息可以直接用return student;此时在前端jquery中的回调函数function(result){}中的result就是控制器层的那个学生数据可以通过遍历取出来,如果是ruturn "student"则是返回一个页面,但记得此时必须在方法上加上@requestbody表示返回一个json字符串)!! 向上转型目的:这是为了面向接口编程,多态化而设计的 @modelattrobite注解表示在程序执行时,最先执行这个注解的方法 A。在controller控制器中每个方法的前面需要加上RequestMapping(); eg:RequestMapping("index") pulib ModelAndView index(){ ModelAndView mv=new ModelAndView("success"); return mv } (redirect:/index)含义就是通过控制器重定向定位到index这里,再进入success.jsp页面中 当输入localhost:8080/ssm/XXX XXX的含义就是你controller控制器里方法前的那个RequestMapping("XXX")的XXX,由此进入,再通过ModelAndView mv=new ModelAndView("success")

JPA confusion (managed vs non-managed entities)

十年热恋 提交于 2019-11-29 14:14:59
问题 I'm working on a web project, trying to understand the best way to do this sort of thing over and over again: Read object A from the DB Later on, read another object ( B ) Make changes to A and B in the DB (as part of a transaction - write all the changes or none) The old-skool JDBC-type way isn't a problem, but JPA is doing my head in. I need there to be a clear demarcation as to where the DB changes occur, and from what I've observed any changes to managed entities will be modified the next

设计模式之门面模式(外观模式) (十一)

旧时模样 提交于 2019-11-29 12:42:03
说到了门面模式,有些地方又叫做外观模式,这个模式在平时做Web项目中应该是经常用到,像我们的Service层与DAO层,就是用到了门面模式,Controller层本来是需要跟一个个DAO打交道,但是有了Service层,它直接与DAO打交道,Controller就可以直接使用Service,我们只需专注在Service上写业务逻辑与操作DAO的各种方法,分离了责任,这个模式我认为最重要的功能就是解耦,降低了系统复杂度。 定义:外观模式是软件工程中常用的一种软件设计模式。它为子系统中的一组接口提供一个统一的高层接口。这一接口使得子系统更加容易使用。 定义与类图来自百度百科。 我们可以从定义与类图知道,门面模式就是为所有的子系统提供一个统一的高层的接口,负责子系统集合的功能的使用,下面举个例子,更清晰的了解这个模式。这里我举个在京东买键盘鼠标的例子。 首先是各个子系统,也就是各个京东的店家,有卖电脑的实体店,有卖键盘的实体店。 package test; public class ComputerStore { public void getComputer() { System.out.println("从仓库里拿电脑"); } public void sendComputer() { System.out.println("让快递把电脑寄给买家"); } } package

Standard Naming Convention for DAO Methods

你。 提交于 2019-11-29 12:35:13
问题 Is there a standard naming convention for DAO methods, similar to JavaBeans? For example, one naming convention I've seen is to use get() to return a single entity and find() to return a List of entities. If there isn't one, what's the one your team is using and why? 回答1: Usually I name the methods in such way that the name hints the type of the CRUD operation that will be applied by the method, like add* , save* or find* . add* can be applied on INSERT operations, like addPhoneNumber(Long

Using Static methods or none static methods in Dao Class?

狂风中的少年 提交于 2019-11-29 12:07:53
问题 Hi I generate Dao classes for some DB operations in this manner making methods of Dao class as static or none static is better? Using sample dao class below ,İf more than one client got to use the AddSampleItem method in same time?how this may result? public class SampleDao { static DataAcessor dataAcessor public static void AddSampleItem(object[] params) { dataAcessor =new DataAcessor(); //generate query here string query="..." dataAcessor.ExecuteQery(query); dataAcessor.Close(); } public

Maven + SSM环境搭建

本秂侑毒 提交于 2019-11-29 12:07:36
Maven + SSM 之前Maven+SSM都是照着搭建的,自己想写点什么的时候发现搭建的过程不清楚。 于是花了时间边整理思路边搭建,并把搭建过程记录下来。 视频看来终觉浅,还是需要自己动手实践,捋顺思路记忆才会深刻。 构建Maven相关工程和模块 首先创建一个父工程,选择Maven Project选项。 勾选上Create a simple project,然后点击next 注意父工程打包方式为pom 点击finish,父工程创建完成。 将鼠标移动到之前创建好的demo-parent,点击鼠标右键,选择Maven->New Maven Module Project. (也可直接创建Maven Module然后指定parent。) 模块名为demo-dao,Parent Project为demo-parent. 注意打包方式为jar,点击finish即可,demo-dao模块就创建完成了。 按照相同的方法创建Service模块,注意打包方式也为jar。 接下来创建demo-web 此处注意打包方式为war 创建完demo-web后会发现,报错这时因为打包为war,因为标准的web程序结构, 而我们目录结构的webapp下缺少WEB-INF文件夹和web.xml文件。 接下来我们创建一个WEB-INF文件夹,然后在其中创建一个空的web.xml文件。 web.xml内容如下所示:

JPA @Version: how to use it?

坚强是说给别人听的谎言 提交于 2019-11-29 11:48:20
问题 @Entity public class Person { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id; private int salary; @Version private long version; // ...getters and setters } Is it required to create setter/getter for version ? When persisting this entity with Hibernate, I don't need to set this value manually, right? What else do I need to configure in order to use optimistic concurrency checking with Spring's hibernateTemplate.saveOrUpdate ? Are all databases supported? How to unit