Re: Wicket-Spring Hibernate dao
Thanks everyone. I will go for using the new operator for my domain object since there is no simple way to inject and it is not really nescessary to inject bean to object in this case. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-Spring-Hibernate-dao-tp3320134p3332713.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket-Spring Hibernate dao
I believe you want to look into using a factory to create your cats. You can inject DAOs and whatever you want into your factory. The factory would be a spring-managed bean, but the entities wouldn't. On Wed, Mar 2, 2011 at 10:36 PM, ookpalm ookp...@gmail.com wrote: Thanks everyone. I will go for using the new operator for my domain object since there is no simple way to inject and it is not really nescessary to inject bean to object in this case. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-Spring-Hibernate-dao-tp3320134p3332713.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket-Spring Hibernate dao
you should be doing cat=new cat() anyways. i assume the default cat is a singleton in your application context, in which case you do not want it to be persisted anyways. -igor On Tue, Feb 22, 2011 at 1:59 PM, ookpalm ookp...@gmail.com wrote: Hi I have a question about wicket spring. My project is setup with Wicket-Spring plus using Hibernate annotation. I created a Dao object says CatDao and created a entity for relational mapping with hibernate says Cat. Both are created by using Spring applicationContext file. On my page says AddCat I show the default values of Cat object that I set in my applicationContext which is rendered correctly in textFields (Wicket-spring works correctly). But when I use the command catDao.store(cat); The following error happens: Last cause: Unknown entity: WICKET_com.ook.Cat$$EnhancerByCGLIB$$d80b8019 I commented out the @SpringBean annotation of the varriable Cat in my AddCat page and used the operator new directly to the Cat object like Cat cat = new Cat(); The CatDao still remains the same @SpringBean CatDao catDao; now the command catDao.store(cat); works fine. Data are written to the Database. I have no clue how to solve this. Please help. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-Spring-Hibernate-dao-tp3320134p3320134.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket-Spring Hibernate dao
I think that it happened because spring wrapped a proxy around your bean, and then hibernate couldn`t recognize its class and which table it should look for. I`m not sure if you can get around it, but I agree with Igor that you should create your domain objects with new, rather than inject them. you should be doing cat=new cat() anyways. i assume the default cat is a singleton in your application context, in which case you do not want it to be persisted anyways. -igor On Tue, Feb 22, 2011 at 1:59 PM, ookpalmookp...@gmail.com wrote: Hi I have a question about wicket spring. My project is setup with Wicket-Spring plus using Hibernate annotation. I created a Dao object says CatDao and created a entity for relational mapping with hibernate says Cat. Both are created by using Spring applicationContext file. On my page says AddCat I show the default values of Cat object that I set in my applicationContext which is rendered correctly in textFields (Wicket-spring works correctly). But when I use the command catDao.store(cat); The following error happens: Last cause: Unknown entity: WICKET_com.ook.Cat$$EnhancerByCGLIB$$d80b8019 I commented out the @SpringBean annotation of the varriable Cat in my AddCat page and used the operator new directly to the Cat object like Cat cat = new Cat(); The CatDao still remains the same @SpringBean CatDao catDao; now the command catDao.store(cat); works fine. Data are written to the Database. I have no clue how to solve this. Please help. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-Spring-Hibernate-dao-tp3320134p3320134.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket-Spring Hibernate dao
Hi, Is your DAO marked with @Repository annotation? e.g. *@Repository(myDao)* public class SomeDAO extends HibernateSessionDao implements IDao { Plus in your client you need that @SpringBean,((Spring would inject it) In my case I use a Service to get to the DAO - May not be necessary @SpringBean( name = serviceName) private IService service; The IService Impl is define like this @Service(serviceName) So Client calls the Service and the Service delegates to the DAO. I think its something to do with the markup/annotation and probably missing the configuration. Hope this helps niv On Wed, Feb 23, 2011 at 6:26 AM, Dan Griffin dangri...@gmail.com wrote: I think that it happened because spring wrapped a proxy around your bean, and then hibernate couldn`t recognize its class and which table it should look for. I`m not sure if you can get around it, but I agree with Igor that you should create your domain objects with new, rather than inject them. you should be doing cat=new cat() anyways. i assume the default cat is a singleton in your application context, in which case you do not want it to be persisted anyways. -igor On Tue, Feb 22, 2011 at 1:59 PM, ookpalmookp...@gmail.com wrote: Hi I have a question about wicket spring. My project is setup with Wicket-Spring plus using Hibernate annotation. I created a Dao object says CatDao and created a entity for relational mapping with hibernate says Cat. Both are created by using Spring applicationContext file. On my page says AddCat I show the default values of Cat object that I set in my applicationContext which is rendered correctly in textFields (Wicket-spring works correctly). But when I use the command catDao.store(cat); The following error happens: Last cause: Unknown entity: WICKET_com.ook.Cat $$EnhancerByCGLIB$$d80b8019 I commented out the @SpringBean annotation of the varriable Cat in my AddCat page and used the operator new directly to the Cat object like Cat cat = new Cat(); The CatDao still remains the same @SpringBean CatDao catDao; now the command catDao.store(cat); works fine. Data are written to the Database. I have no clue how to solve this. Please help. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-Spring-Hibernate-dao-tp3320134p3320134.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket + Spring + Hibernate - Wicket-In-Action
The interceptor can be safely removed. It was necessary for the project I was working on, but you probably don't need it. JDBC connection settings are best done through a DataSource and specified at the container level instead of programmatically. Martijn On Mon, Nov 16, 2009 at 6:38 PM, Jeffrey Schneller jeffrey.schnel...@envisa.com wrote: At the link[1] it describes how to configure wicket to use Spring and Hibernate. In the applicationContext.xml file there is reference to a n interceptor bean. What is this interceptor bean? What is the definition of this bean? Everything else seems to make sense. Also how would one move the configuration of the jdbc connection to code? It is desirable to db connection information reside at the server level so when deploying code from dev to stage to production, you do not need change or replace a file. The configuration is at the server level [in the server context] and it is pulled from there. Thanks. [1] http://wicketinaction.com/2009/06/wicketspringhibernate-configuration/ -- Become a Wicket expert, learn from the best: http://wicketinaction.com Apache Wicket 1.4 increases type safety for web applications Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0 - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket + Spring + Hibernate - Wicket-In-Action
The interceptor can be safely removed. It was necessary for the project I was working on, but you probably don't need it. JDBC connection settings are best done through a DataSource and specified at the container level instead of programmatically. Martijn On Mon, Nov 16, 2009 at 6:38 PM, Jeffrey Schneller jeffrey.schnel...@envisa.com wrote: At the link[1] it describes how to configure wicket to use Spring and Hibernate. In the applicationContext.xml file there is reference to a n interceptor bean. What is this interceptor bean? What is the definition of this bean? Everything else seems to make sense. Also how would one move the configuration of the jdbc connection to code? It is desirable to db connection information reside at the server level so when deploying code from dev to stage to production, you do not need change or replace a file. The configuration is at the server level [in the server context] and it is pulled from there. Thanks. [1] http://wicketinaction.com/2009/06/wicketspringhibernate-configuration/ -- Become a Wicket expert, learn from the best: http://wicketinaction.com Apache Wicket 1.4 increases type safety for web applications Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0 - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket + Spring + Hibernate - Wicket-In-Action
On Mon, Nov 16, 2009 at 12:38 PM, Jeffrey Schneller jeffrey.schnel...@envisa.com wrote: Also how would one move the configuration of the jdbc connection to code? It is desirable to db connection information reside at the server level so when deploying code from dev to stage to production, you do not need change or replace a file. The configuration is at the server level [in the server context] and it is pulled from there. Isn't this a Spring question? The Wicket/Spring integration basically lets you talk to your Spring beans (by using @SpringBean annotation to inject them). It doesn't do anything fancy with Spring itself. You don't even use a Wicket way to bootstrap the context (you use Spring's context listener for that). How you configure your Spring beans is up to you. I'd recommend either picking up Spring in Action or just read the online documentation (it's pretty good). - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
RE: Wicket + Spring + Hibernate - Wicket-In-Action
I'm not sure the purpose of the interceptor, but until you have a need to extend and use it, you can use the org.hibernate.EmptyInterceptor class instead of creating your own. I have had no problems with using that class. -Original Message- From: Jeffrey Schneller [mailto:jeffrey.schnel...@envisa.com] Sent: Monday, November 16, 2009 12:38 PM To: users@wicket.apache.org Subject: Wicket + Spring + Hibernate - Wicket-In-Action At the link[1] it describes how to configure wicket to use Spring and Hibernate. In the applicationContext.xml file there is reference to a n interceptor bean. What is this interceptor bean? What is the definition of this bean? Everything else seems to make sense. Also how would one move the configuration of the jdbc connection to code? It is desirable to db connection information reside at the server level so when deploying code from dev to stage to production, you do not need change or replace a file. The configuration is at the server level [in the server context] and it is pulled from there. Thanks. [1] http://wicketinaction.com/2009/06/wicketspringhibernate-configuration/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: wicket+guice+hibernate
http://www.cafesolo.com.ar/2008/10/22/wicket-guice-warp-and-hibernate-a-quickstart-project/ francisco On Wed, Mar 18, 2009 at 4:57 PM, srividh...@yahoo.com wrote: I am a newbie to wicket and guice . I would like to look at some examples of the trio before starting to use them for my project. Can somebody point me to them? thanks Vidhya - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket/Salve/Hibernate Examples
Francisco, Thanks! Actually, I was just reading that post of Igor's which prompted my question. But I was hoping there might be an integrated sample app (or maven archetype would be even better!) to experiment with to save me the time of putting it all together. Anyone else know of any samples or open projects using this combination that I could check out? Thanks, Tauren On Thu, Jan 22, 2009 at 8:46 AM, francisco treacy francisco.tre...@gmail.com wrote: not an app, but maybe this helps: http://wicketinaction.com/2008/09/building-a-smart-entitymodel/ francisco On Thu, Jan 22, 2009 at 5:06 PM, Tauren Mills tau...@tauren.com wrote: Can anyone point me to any example applications that are along the lines of Wicketstuff Phonebook, but that utilize Salve and Hibernate? Does anything like that exist? Thanks, Tauren - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket/Salve/Hibernate Examples
http://code.google.com/p/elephas/source/browse/#svn/trunk for instance, http://code.google.com/p/elephas/source/browse/trunk/src/main/java/org/elephas/model/Blog.java francisco On Thu, Jan 22, 2009 at 6:09 PM, Tauren Mills tau...@tauren.com wrote: Francisco, Thanks! Actually, I was just reading that post of Igor's which prompted my question. But I was hoping there might be an integrated sample app (or maven archetype would be even better!) to experiment with to save me the time of putting it all together. Anyone else know of any samples or open projects using this combination that I could check out? Thanks, Tauren On Thu, Jan 22, 2009 at 8:46 AM, francisco treacy francisco.tre...@gmail.com wrote: not an app, but maybe this helps: http://wicketinaction.com/2008/09/building-a-smart-entitymodel/ francisco On Thu, Jan 22, 2009 at 5:06 PM, Tauren Mills tau...@tauren.com wrote: Can anyone point me to any example applications that are along the lines of Wicketstuff Phonebook, but that utilize Salve and Hibernate? Does anything like that exist? Thanks, Tauren - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: wicket and hibernate
You said you were using annotations. Just read chapter 1 of the hibernate annotations docs http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/#setup-configuration create a class called HibernateUtil.class (or you can call it Fluffy.class, but that's not as descriptive) and add a static SessionFactory. public static final SessionFactory sessionFactory; Then add an initialize method to add your annotated classes with this: AnnotationConfiguration cfg = new AnnotationConfiguration(); cfg.configure(); sessionFactory = cfg .setInterceptor(new AuditInterceptor()) .addAnnotatedClass(User.class) //others as needed .buildSessionFactory(); The WebApplication object for your project has an init() method. You can call the above method from there. When wicket starts up, it will call that init() method first, so you can do things like setup your app. Or just wrap the above in a static block and you don't have to worry about it. The first time you access the HibernateUtil, the class loader will run the static block. Then in your methods you can just get a connection from the pool. Session session = HibernateUtil.sessionFactory.openSession(); I do this a little differently than hibernate examples. In the service, I open the connection, get all the data I need and close the connection at the end of the method. The way Hibernate works is when your working thread gets a connection, hibernate attaches that connection to the thread. So throughout the lifecycle you can make references to related objects and hibernate will go fetch them for you. I don't like that technique, personally. HTH -- View this message in context: http://www.nabble.com/wicket-and-hibernate-tp19767474p19791416.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: wicket and hibernate
Hi, Have a look at http://wicketstuff.org/confluence/display/STUFFWIKI/Wicket-Iolite overseastars a écrit : Hi I just wanna know how to integrate wicket and hibernate?? can someone give me a simple example even just one entity is ok. I have my entities(hibernate annotation) ready and I have no ideas of making them work together. If any buddy can send me an example project, I will really appreciate it. Thanks in advance. Regards - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: wicket and hibernate
Here's how I do it. I have my wicket layer call a service layer, which calls a DAO. I'm not a big fan of a lot of layers and I like to keep my projects flat. So, if you want a list of users on a page, for example, you can use any of the canned wicket tables. Those are pretty nice. I use DefaultDataTable unless I need something special. So in your page class you do something like DefaultDataTable defaultDataTable = new DefaultDataTable(table, columnsList, new SortableUserDataProvider(userFilter), 10); If this doesn't make sense look at the DefaultDataTable.java class in the wicket examples. In my SortableUserDataProvider, I pass in a filter obj depending on what the user is asking for. This includes any search criteria, sort options, paging, etc. My SortableUserDataProvider calls my service. That preps the hibernate query and calls my dao. So for the SortableUserDataProvider you want to override the iterator() method, something like: public IteratorUser iterator(int first, int count) { SortParam sp = getSort(); userFilter.setFirstRecord(first); userFilter.setRecordsToReturn(count); userFilter.setSortCol(sp.getProperty()); userFilter.setSortAsc(sp.isAscending()); return UserService.getUsers(userFilter).iterator(); } I prep my queries in my service layer. So something like Criteria userCriteria = session.createCriteria(User.class) .setFirstResult(filter.getFirstRecord()) //other filter info here as needed ListUser userList = userCriteria.list(); Hibernate returns models and lists of models, and wicket uses models and lists of models. The only catch with this is your web layer is getting hibernate aware models, not POJOs. So if it's a closed system where nobody else hits your hibernate code, you're fine. If the service layer is an SOA type arch, you'll need to convert your hibernate models (or the list), to equivalent pojos on select and vice-versa on saves. The only thing I did which I regret was I defined my collections in hibernate as Lists instead of sets. I did this because wicket takes a list as a param in a lot of places and Lists are generally easier to work with. But hibernate treats Lists as bags and when you are doing eager fetches on multiple collections, Hibernate will complain. It won't let you fetch multiple bags simultaneously. It used to though. They keep threatening to fix it. http://opensource.atlassian.com/projects/hibernate/browse/HHH-1718 -- View this message in context: http://www.nabble.com/wicket-and-hibernate-tp19767474p19772328.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: wicket and hibernate
Hi Flavius Very impressive. Many thanks. I learnt a lot. But I still have a question. For example, I know I should use Dao to access the persistence layer. Let's say I have 2 entities which means two classes in java. I put them in the source folder. Once I start the server, I guess they wont help me create the schema and tables because there should be a config file hibernate.cfg.xml. Now I dont have that file, I have a HibernateUtil.java which contains codes like following: public static void main(String[] args) { // TODO Auto-generated method stub // Configuration config = new Configuration().configure(); AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(com.xingxing.autotable.User.class); config.addAnnotatedClass(com.xingxing.autotable.Address.class); config.addAnnotatedClass(com.xingxing.autotable.Person.class); config.addAnnotatedClass(com.xingxing.autotable.CreditCard.class); config.setProperty(hibernate.show_sql, true); config.setProperty(hibernate.format_sql, true); config.setProperty(hibernate.dialect, org.hibernate.dialect.MySQLDialect); config.setProperty(hibernate.connection.driver_class, com.mysql.jdbc.Driver); // config.setProperty(hibernate.connection.createDataBaseIfNotExist, true); config.setProperty(hibernate.connection.url, jdbc:mysql://localhost/test?createDatabaseIfNotExist=true); config.setProperty(hibernate.connection.autocommit, true); config.setProperty(hibernate.connection.username, root); config.setProperty(hibernate.connection.password, passw0rd); config.setProperty(c3p0.min_size, 5); config.setProperty(c3p0.max_size, 20); config.setProperty(c3p0.timeout, 1800); config.setProperty(c3p0.max_statements, 50); config.setProperty(hibernate.hbm2dll.auto, create); System.out.println(Creating Tables.); SchemaExport schemaExport = new SchemaExport(config); schemaExport.create(true, true); } How can I just this code to run my Eclipse Dynamic Web Project so that it will create the schema and tables I need more java files?? Or I have to use hibernate.cfg.xml file ?? Even if the above is not a Main function, I guess I have to call this part from somewhere in wicket layer? Would you please show me a way.. Regards Flavius wrote: Here's how I do it. I have my wicket layer call a service layer, which calls a DAO. I'm not a big fan of a lot of layers and I like to keep my projects flat. So, if you want a list of users on a page, for example, you can use any of the canned wicket tables. Those are pretty nice. I use DefaultDataTable unless I need something special. So in your page class you do something like DefaultDataTable defaultDataTable = new DefaultDataTable(table, columnsList, new SortableUserDataProvider(userFilter), 10); If this doesn't make sense look at the DefaultDataTable.java class in the wicket examples. In my SortableUserDataProvider, I pass in a filter obj depending on what the user is asking for. This includes any search criteria, sort options, paging, etc. My SortableUserDataProvider calls my service. That preps the hibernate query and calls my dao. So for the SortableUserDataProvider you want to override the iterator() method, something like: public IteratorUser iterator(int first, int count) { SortParam sp = getSort(); userFilter.setFirstRecord(first); userFilter.setRecordsToReturn(count); userFilter.setSortCol(sp.getProperty()); userFilter.setSortAsc(sp.isAscending()); return UserService.getUsers(userFilter).iterator(); } I prep my queries in my service layer. So something like Criteria userCriteria = session.createCriteria(User.class) .setFirstResult(filter.getFirstRecord()) //other filter info here as needed ListUser userList = userCriteria.list(); Hibernate returns models and lists of models, and wicket uses models and lists of models. The only catch with this is your web layer is getting hibernate aware models, not POJOs. So if it's a closed system where nobody else hits your hibernate code, you're fine. If the service layer is an SOA type arch, you'll need to convert your hibernate models (or the list), to equivalent pojos on select and vice-versa on saves. The only thing I did which I regret was I defined my collections in hibernate as Lists instead of sets. I did this because wicket takes a list as a param in a lot of places and Lists are generally easier to work with. But