dao

Two classes with almost duplicate code inside

自古美人都是妖i 提交于 2019-12-05 02:20:28
问题 At this moment, I have two classes: UserHibernateDao and TicketHibernateDao : import java.util.List; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import model.dao.Dao; import model.entity.User; public class UserDaoHibernate extends HibernateDaoSupport implements Dao<User> { public User get(long id) { return getHibernateTemplate().get(User.class, id); } public void save(User user) { getHibernateTemplate().save(user); } public void remove(long id) {

Spring/Spring-Boot 学习 入门知识

梦想与她 提交于 2019-12-05 02:07:28
在Spring/Spring-Boot的入门上我绕了很多弯路,我绕过的一个典型的弯路是: 找一个Spring-Boot的入门案例,下载代码跟着跑了一遍,跑通之后确不能理解代码,尤其是各种配置文件以及注解让我难以理解这个程序究竟是怎么跑起来的。@Autowired, @Controller这些注解到底是什么意思,它的工作流程是怎样的? 我怀疑自己是注解相关的知识没有学好,于是往下挖注解的工作原理-->动态代理机制-->反射-->类加载过程-->类加载器的工作原理。这样一套走下来之后,即使我懵懵懂懂明白了类加载器、反射、动态代理、注解, 我还是不能看懂spring的这些注解是怎么工作的,也不知道怎么去实际使用他们。 很多的入门教程,给出了很多具体的操作,但是并没有告诉我们为什么spring要用这个注解,这个注解用了之后他会有什么作用,以及这些注解的工作流程(我指的是使用流程不是底层的实现原理)。 下面是我自己的一些学习反思。 首先我们从最基本的需求讲起。 java是面向对象的语言,每个对象都可以绑定一定的操作,通过将多个对象组合,我们可以完成一个任务所需要的所有操作。 举个例子,假设我们的任务是接收用户对 localhost:8080/user 这个链接的get请求,返回给用户浏览器一个含有用户数据的json数据串 “{"name":"bob"}”。我们把这个任务分成到多个对象去完成

Hibernate 5.2 version -> A lot of Query methods deprecate?

久未见 提交于 2019-12-04 23:45:26
I'm new to Hibernate. I'm trying to get a list of first name and last name of all administrators. There are two warnings in my following code. I already tried to search a lot online. 1) Query is a raw type. References to generic type Query should be parameterized. 2) The method list() from the type Query is deprecated. public List<Object> loadAllAdmins() { List<Object> allAdmins = new ArrayList<Object>(); try { HibernateUtil.beginTransaction(); Query q = currentSession.createQuery("SELECT admin.firstName, admin.lastName from AdminBean admin"); allAdmins= q.list(); HibernateUtil

How to insert “Entire” DAO recordset into a table with VBA

て烟熏妆下的殇ゞ 提交于 2019-12-04 23:16:20
问题 I have a DAO recordset that gets created fine and I can transfer the records from the set to a table, this is done row by row and works well but I am transfering a large amount of data at once so this can take a very long time row by row. Is there a way to transfer the ENTIRE recordset in one go, rather than row by row See below for current code in use - Dim SendE1 As DAO.Recordset Set SendE1 = CurrentDb.OpenRecordset("SELECT TBL_ImportTable.* FROM TBL_ImportTable", dbOpenDynaset) SendE1

DAO pattern in java what is a Business Object

六眼飞鱼酱① 提交于 2019-12-04 22:37:42
问题 Directly from this oracle article about the J2EE DAO Pattern: Everything is very clear indeed but the Business Object "participant" (as they call it). Here I quote the bit I would like more insights about (especially would be useful a real life example (an easy one)). BusinessObject The BusinessObject represents the data client. It is the object that requires access to the data source to obtain and store data. A BusinessObject may be implemented as a session bean, entity bean, or some other

Difference between Active Record and DAO?

你离开我真会死。 提交于 2019-12-04 22:27:12
What's the difference between a Data Access Object and Active Record? They seem to be quite the same, as both built a layer between the application and persistence layer, and abstract away direct database access using SQL queries. Data Access Object (DAO) refers to an object in your data layer responsible for persisting a separate entity in your domain. Active Record is a specific method of doing a DAO where the class containing the values of a single row from a table is also responsible for queries, updates, inserts, and deletes to that table. The Active Record design pattern means your

How do we determine an object's responsibility in OOP?

岁酱吖の 提交于 2019-12-04 19:36:18
I just started learning OOP and I'm finding it really hard to decide where functionality belongs. Let's use a down vote in SO for our example: When we cast one, the following must happen in a transaction: Decrement the voter's rep and downVotes count. Decrement the recipient's rep . Decrement the post score . So... How do we determine which action belongs to which object? Where would such functionality live? In the DAO layer, services layer, or the actual objects themselves? It becomes increasingly tricky when objects interact with each other, such as in my example. It's often hard to decide

One DAO per 'container' class or one DAO per table?

前提是你 提交于 2019-12-04 18:51:43
问题 I have a 'container' class with fields that are contained in several database tables, and I use the DAO pattern for accessing the data. The question is, should I create a single DAO for this 'container' class, or is it better to have one DAO per table and combine their data? 回答1: You should design your DAO according to your application needs, not the layout of your database. Start of with one DAO, and if it becomes too large, then refactor it into multiple DAOs in a way that makes sense to

EJB3 vs Data Access Objects

跟風遠走 提交于 2019-12-04 18:29:07
I am working on a project where we need to decide how we are going to expose our persistence layer. There are currently two options on the table: 1) Use plain DAOs. These would implement an interface and be injected (probably using Weld) in the Business Components which are EJBs. Internally they would use JPA/Hibernate for persistence. 2) Rather than injecting the DAOs using Weld, they would be implemented as EJBs, and injected with @EJB in the Business Components. Does it really make sense to use EJBs for the persistence layer when we are not using its capabilities (e.g. transaction

Maven学习总结(八)——使用Maven构建多模块项目

余生颓废 提交于 2019-12-04 18:01:15
https://ask.csdn.net/questions/239471   在平时的Javaweb项目开发中为了便于后期的维护,我们一般会进行分层开发,最常见的就是分为domain(域模型层)、dao(数据库访问层)、service(业务逻辑层)、web(表现层),这样分层之后,各个层之间的职责会比较明确,后期维护起来也相对比较容易,今天我们就是使用Maven来构建以上的各个层。   项目结构如下:   system-parent     |----pom.xml     |----system-domain         |----pom.xml     |----system-dao         |----pom.xml     |----system-service         |----pom.xml     |----system-web         |----pom.xml 一、创建system-parent项目   创建system-parent,用来给各个子模块继承。   进入命令行,输入以下命令: mvn archetype:create -DgroupId=me.gacl -DartifactId=system-parent -DarchetypeArtifactId=maven-archetype-quickstart