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 Iterator<User> 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
> 
> List<User> 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-tp19767474p19773409.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]

Reply via email to