Using the DAO object of ZetaDB Form Builder ?

asked 2009-06-05 08:40:37 +0800

TLHP gravatar image TLHP
111 1 3

Hi everybody,

I want to know how can we use the class DAO generated by ZetaDB Form Builder for other purpose?
For example in my class, i want to use a object DAO to to the access into database, but this object is always null, how can I initialize it ???

public class Test
  ItemDAO itemDAO; 
  public boolean checkExistance(int idItem)
      Item item  = itemDAO.find(idItem);  (Here java.lang.NullPointerException is raised)
    catch (EntityNotFoundException e)
      // TODO Auto-generated catch block

Thanks in advance

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2009-06-05 17:20:16 +0800

robertpic71 gravatar image robertpic71
1275 1

Could you check/post your spring-config?

<!-- ZK Spring config -->
<zksp-annot:component-scan base-package="org.zkoss.spring.jpa,org.zkforge.todo" />
<zksp:zk-config />

The DAO's extends the BasicDAO inside the org.zkoss.spring.jpa-package. You have to configure spring to scan the zk-package. W/o zk-package no EntityManager will be injected.


link publish delete flag offensive edit

answered 2009-06-07 22:07:27 +0800

TLHP gravatar image TLHP
111 1 3

thanks Robert, here my test

- I create a ZK project, use ZETA Form Builder to build a CRUD application
- CheckDAO.java , i just want to use a DAO class generated by ZETA to search a bean from database and show one of those attribut via showTheName method.

package testDAO;

import javax.annotation.Resource;
import org.zkoss.spring.jpa.EntityNotFoundException;

import test.help_topic.Help_topicDAO;
import test.help_topic.base.Help_topic;

public class CheckDAO {
	Help_topicDAO helpDAO;
	public String showTheName()
		try {
			Help_topic helpBean = helpDAO.find(1); // find bean with ID=1
			return helpBean.getName();
		} catch (EntityNotFoundException e) {			
			// TODO Auto-generated catch block
			return "Bean not found";

- application-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.1.xsd
    http://www.zkoss.org/2008/zkspring http://www.zkoss.org/2008/zkspring/zkspring.xsd
    http://www.zkoss.org/2008/zkspring-annot http://www.zkoss.org/2008/zkspring-annot/zkspring-annot.xsd
	ZK Spring config 
	<zksp-annot:component-scan base-package="org.zkoss.spring.jpa,test,testDAO"/>
    Injected properties
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
	    <property name="locations">

Robert, if you did that work, let me know or show me some code, I appreciate that


link publish delete flag offensive edit

answered 2009-06-19 19:33:50 +0800

TLHP gravatar image TLHP
111 1 3

Still need help ...


link publish delete flag offensive edit

answered 2009-11-19 01:09:20 +0800

iantsai gravatar image iantsai
2755 1

You declared a Test class here means it also need to be managed by Spring.

Why not just use Spring BeanFactory to get ItemDAO instance back at very first?

link publish delete flag offensive edit

answered 2009-11-19 21:51:32 +0800

jeanher gravatar image jeanher
1719 1 6
ZK Team

I have done this but when I do it I can get the bean but the basic dao service inside it is null.

- by Jacques

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2009-06-05 08:40:37 +0800

Seen: 1,869 times

Last updated: Nov 19 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More