dao

Java EE Architecture - Are DAO's still recommended when using an ORM like JPA 2?

杀马特。学长 韩版系。学妹 提交于 2019-11-26 11:51:58
问题 If I\'m using an ORM like JPA2 - where I have my entities that are mapped to my database, should I still be using a DAO? It seems like a lot more overhead. For example, I would need to maintain three extra packages: One that specifies my domain objects (which pretty much map my Entity objects): public class Employee { private String firstName; private String lastName; ... // Getters and setters } One that contains interfaces that specify my DAO methods public interface EmployeeDAO { public

Struts + Hibernate: @SessionTarget not working

五迷三道 提交于 2019-11-26 11:28:16
问题 I am using struts2-fullhibernatecore-plugin-2.2.2-GA.jar to inject a session in my DAO class like below: public class UserDAO { @SessionTarget Session session; @TransactionTarget Transaction transaction; public List<User> getUsers() { return session.createQuery(\"from user\").list(); } } But I got java.lang.NullPointerException com.wudi.DAO.UserDAO.getUsers(UserDAO.java:28) com.wudi.action.UserListAction.execute(UserListAction.java:24) sun.reflect.NativeMethodAccessorImpl.invoke0(Native

Responsibilities and use of Service and DAO Layers

荒凉一梦 提交于 2019-11-26 10:35:23
问题 I am currently developing a web application using Struts2 with Spring plugin and hibernate and while I was looking at online examples I saw the use of Service and DAO layers now it came to me what are the real use of Service and data access object layers? If The Service layer is just calling the methods of DAO layers to perform CRUD operations. wouldn\'t be sensible to just call the DAO layers methods directly? Let\'s say this example of Dao and Service Layer PeopleService @Transactional

javaBean和数据层的DAO设计模式

我们两清 提交于 2019-11-26 10:09:39
jsp:javaBean 一、javaBean简介 javaBean是使用java语言开发的一个人可重用的组件,在jsp开发中可以使用javaBean减少重复的代码,是一种特殊的java类,使用java语言编写,遵循javaBean API规范 优点 将html和java代码分离,这主要是为了日后的维护方便 减少代码重复 在jsp中如果要应用jsp提供的javaBean的标签来操作简单类,则此类要满足以下要求: 所有类都要在一个包中,在web项目中没有包的类时不存在的。 所有类必须是public修饰,这样才能被外界访问。 提供一个默认的无参构造函数。 需要被序列化并且实现了 Serializable 接口。 可能有一系列可读写属性。(可能的意思就是除了private修饰的字段,也可以有其他修饰符修饰的字段,但是必须至少要有一个private修饰的字段) 可能有一系列的 getter 或 setter 方法。 二、在jsp中使用javaBean 一个javaBean编写结束后,需要进行打包编译,那么存放到哪里呢? classes目录保存所有的javaBean,如果不存在则可以手动创建(WEBAPP/WEB-INFO/classes) 引入useBean 打包编译 直接使用javac -d.类名,根据该类的路径的定义来打包编译变为class文件,在web开发中

Data access object (DAO) in Java

故事扮演 提交于 2019-11-26 09:11:56
I was going through a document and I came across a term called DAO . I found out that it is a Data Access Object. Can someone please explain me what this actually is? I know that it is some kind of an interface for accessing data from different types of sources, in the middle of this little research of mine I bumped into a concept called data source or data source object, and things got messed up in my mind. I really want to know what a DAO is programmatically in terms of where it is used. How it is used? Any links to pages that explain this concept from the very basic stuff is also

Single DAO & generic CRUD methods (JPA/Hibernate + Spring)

南笙酒味 提交于 2019-11-26 08:43:59
问题 Following my previous question, DAO and Service layers (JPA/Hibernate + Spring), I decided to use just a single DAO for my data layer (at least at the beginning) in an application using JPA/Hibernate, Spring and Wicket. The use of generic CRUD methods was proposed, but I\'m not very sure how to implement this using JPA. Could you please give me an example or share a link regarding this? 回答1: Here is an example interface: public interface GenericDao<T, PK extends Serializable> { T create(T t);

Get actual type of generic type argument on abstract superclass

喜你入骨 提交于 2019-11-26 07:44:34
问题 I have a class like: public abstract class BaseDao<T extends PersistentObject> { protected Class<T> getClazz() { return T.class; } // ... } But the compiler says to T.class; : Illegal class literal for the type parameter T . How can I get the class of T ? 回答1: It's definitely possible to extract it from Class#getGenericSuperclass() because it's not defined during runtime, but during compiletime by FooDao extends BaseDao<Foo> . Here's a kickoff example how you could extract the desired generic

Spring + Hibernate : a different object with the same identifier value was already associated with the session

本小妞迷上赌 提交于 2019-11-26 05:36:28
问题 In my application, which uses Spring and Hibernate, I parse a CSV file and populate the db by calling handleRow() every time a record is read from the CSV file. My domain model: \'Family\' has many \'SubFamily\' \'SubFamily\' has many \'Locus\' a \'Locus\' belongs to a \'Species\' Family <-> SubFamily <-> Locus are all bi-directional mappings. Code: public void handleRow(Family dummyFamily, SubFamily dummySubFamily, Locus dummyLocus) { //Service method which access DAO layers CommonService

I found JPA, or alike, don&#39;t encourage DAO pattern

天涯浪子 提交于 2019-11-26 03:52:32
问题 I found JPA, or alike, don\'t encourage DAO pattern. I don\'t know, but I feel like that, especially with server managed JTA managers. After adequate hands-on using DAO pattern, I started designing JPA based application around that pattern. But it doesn\'t fit in, IMO. I tend to lose quite a features of JPA and all. Well, suppose you fire a query with pessimistic locking and it returned a list of entites from a DAO method. Upon returning, transaction ends and lock is gone (a case with server

Writing large number of records (bulk insert) to Access in .NET/C#

风流意气都作罢 提交于 2019-11-26 02:08:50
问题 What is the best way to perform bulk inserts into an MS Access database from .NET? Using ADO.NET, it is taking way over an hour to write out a large dataset. Note that my original post, before I \"refactored\" it, had both the question and answer in the question part. I took Igor Turman\'s suggestion and re-wrote it in two parts - the question above and followed by my answer. 回答1: I found that using DAO in a specific manner is roughly 30 times faster than using ADO.NET. I am sharing the code