I'm trying to recreate the masterDetail example in the showcase using hibernate annotations. I have it working using hbm.xml files as in the showcase example, but when I switch to using annotations i get this error when loading the datasource.
I found another post with a solution for smartclient, however I am using smartGWT.
http://forums.smartclient.com/showthread.php?t=10915
Version:
SmartGWT EE 2.3 EVAL Deployment 2010-12-02
FF 3.6
Error:
masterDetail_order.ds.xml
hibernate.cfg.xml
Order.java
The hibernate configuration loads correctly via spring. Note the configuration class is set to org.hibernate.cfg.AnnotationConfiguration.
applicationContext.xml
Please help.
I found another post with a solution for smartclient, however I am using smartGWT.
http://forums.smartclient.com/showthread.php?t=10915
Version:
SmartGWT EE 2.3 EVAL Deployment 2010-12-02
FF 3.6
Error:
Code:
[Server@ce2187]: [Thread[main,5,main]]: checkRunning(false) entered [Server@ce2187]: [Thread[main,5,main]]: checkRunning(false) exited [Server@ce2187]: Startup sequence initiated from main() method [Server@ce2187]: Loaded properties from [C:\springgwt\war\server.properties] [Server@ce2187]: Initiating startup sequence... [Server@ce2187]: Server socket opened successfully in 0 ms. [Server@ce2187]: Database [index=0, id=0, db=file:C:\springgwt\war\WEB-INF\db\hsqldb\isomorphic, alias=isomorphic] opened sucessfully in 203 ms. [Server@ce2187]: Startup sequence completed in 203 ms. [Server@ce2187]: 2010-12-14 12:28:14.156 HSQLDB server 1.8.0 is online [Server@ce2187]: To close normally, connect and execute SHUTDOWN SQL [Server@ce2187]: From command line, use [Ctrl]+[C] to abort abruptly log4j:WARN No appenders could be found for logger (org.apache.jasper.compiler.JspRuntimeContext). log4j:WARN Please initialize the log4j system properly. ISC: Configuring log4j from: file:/C:/springgwt/war/WEB-INF/classes/log4j.isc.config.xml === 2010-12-14 12:28:14,578 [main] INFO ISCInit - Isomorphic SmartClient Framework - Initializing === 2010-12-14 12:28:14,578 [main] INFO ConfigLoader - Attempting to load framework.properties from CLASSPATH === 2010-12-14 12:28:14,625 [main] INFO ConfigLoader - Successfully loaded framework.properties from CLASSPATH at location: jar:file:/C:/springgwt/war/WEB-INF/lib/isomorphic_core_rpc.jar!/framework.properties === 2010-12-14 12:28:14,625 [main] INFO ConfigLoader - Attempting to load project.properties from CLASSPATH === 2010-12-14 12:28:14,625 [main] INFO ConfigLoader - Unable to locate project.properties in CLASSPATH === 2010-12-14 12:28:14,640 [main] INFO ConfigLoader - Successfully loaded isc_interfaces.properties from CLASSPATH at location: jar:file:/C:/springgwt/war/WEB-INF/lib/isomorphic_core_rpc.jar!/isc_interfaces.properties === 2010-12-14 12:28:14,640 [main] INFO ConfigLoader - Attempting to load server.properties from CLASSPATH === 2010-12-14 12:28:14,640 [main] INFO ConfigLoader - Successfully loaded server.properties from CLASSPATH at location: file:/C:/springgwt/war/WEB-INF/classes/server.properties === 2010-12-14 12:28:14,640 [main] INFO Logger - Logging system started. === 2010-12-14 12:28:14,640 [main] INFO ISCInit - Isomorphic SmartClient Framework (SC_SNAPSHOT-2010-12-02/EVAL Deployment 2010-12-02) - Initialization Complete === 2010-12-14 12:28:14,640 [main] INFO ISCInit - Auto-detected webRoot - using: C:\springgwt\war === 2010-12-14 12:28:23,500 [l0-1] INFO PoolManager - SmartClient pooling disabled for 'masterDetail_order' objects === 2010-12-14 12:28:23,546 [l0-1] DEBUG XML - Parsed XML from C:\springgwt\war\ds\masterDetail_order.ds.xml: 0ms === 2010-12-14 12:28:23,546 [l0-1] DEBUG XML - Parsed XML from C:\springgwt\war\SpringGWT_js\sc\system\schema\DataSource.ds.xml: 0ms === 2010-12-14 12:28:23,562 [l0-1] DEBUG XML - Parsed XML from C:\springgwt\war\SpringGWT_js\sc\system\schema\builtinTypes.xml: 0ms === 2010-12-14 12:28:23,656 [l0-1] DEBUG XML - Parsed XML from C:\springgwt\war\SpringGWT_js\sc\system\schema\DataSourceField.ds.xml: 0ms === 2010-12-14 12:28:23,781 [l0-1] DEBUG XML - Parsed XML from (in memory stream): 0ms === 2010-12-14 12:28:23,828 [l0-1] ERROR DataSourceLoader - Exception while attempting to load a DataSource org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com.smartgwt.sample.server.Order"/> at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1634) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1589) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1568) at org.hibernate.cfg.Configuration.configure(Configuration.java:1557) at com.isomorphic.hibernate.HibernateDataSource.initStaticConfigAndSessionFactory(HibernateDataSource.java:425) at com.isomorphic.hibernate.HibernateDataSource.initConfigAndSessionFactory(HibernateDataSource.java:339) at com.isomorphic.hibernate.HibernateDataSource.init(HibernateDataSource.java:179) at com.isomorphic.datasource.BasicDataSource.fromConfig(BasicDataSource.java:165) at com.isomorphic.datasource.DataSource.fromConfig(DataSource.java:337) at com.isomorphic.datasource.FileSystemDSRepo.loadDS(FileSystemDSRepo.java:110) at com.isomorphic.datasource.DataSource.forName(DataSource.java:156) at com.isomorphic.datasource.DataSource.forName(DataSource.java:148) at com.isomorphic.datasource.DataSource.forName(DataSource.java:143) at com.isomorphic.datasource.PoolableDataSourceFactory.makeUnpooledObject(PoolableDataSourceFactory.java:95) at com.isomorphic.datasource.PoolableDataSourceFactory.makeObject(PoolableDataSourceFactory.java:102) at com.isomorphic.pool.PoolManager.borrowObject(PoolManager.java:82) at com.isomorphic.datasource.DataSourceManager.getDataSource(DataSourceManager.java:62) at com.isomorphic.servlet.DataSourceLoader.processRequest(DataSourceLoader.java:81) at com.isomorphic.servlet.DataSourceLoader.doGet(DataSourceLoader.java:64) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:324) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488) === 2010-12-14 12:28:23,828 [l0-1] ERROR DataSourceLoader - Top-level servlet error: javax.servlet.ServletException: org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com.smartgwt.sample.server.Order"/> at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1634) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1589) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1568) at org.hibernate.cfg.Configuration.configure(Configuration.java:1557) at com.isomorphic.hibernate.HibernateDataSource.initStaticConfigAndSessionFactory(HibernateDataSource.java:425) at com.isomorphic.hibernate.HibernateDataSource.initConfigAndSessionFactory(HibernateDataSource.java:339) at com.isomorphic.hibernate.HibernateDataSource.init(HibernateDataSource.java:179) at com.isomorphic.datasource.BasicDataSource.fromConfig(BasicDataSource.java:165) at com.isomorphic.datasource.DataSource.fromConfig(DataSource.java:337) at com.isomorphic.datasource.FileSystemDSRepo.loadDS(FileSystemDSRepo.java:110) at com.isomorphic.datasource.DataSource.forName(DataSource.java:156) at com.isomorphic.datasource.DataSource.forName(DataSource.java:148) at com.isomorphic.datasource.DataSource.forName(DataSource.java:143) at com.isomorphic.datasource.PoolableDataSourceFactory.makeUnpooledObject(PoolableDataSourceFactory.java:95) at com.isomorphic.datasource.PoolableDataSourceFactory.makeObject(PoolableDataSourceFactory.java:102) at com.isomorphic.pool.PoolManager.borrowObject(PoolManager.java:82) at com.isomorphic.datasource.DataSourceManager.getDataSource(DataSourceManager.java:62) at com.isomorphic.servlet.DataSourceLoader.processRequest(DataSourceLoader.java:81) at com.isomorphic.servlet.DataSourceLoader.doGet(DataSourceLoader.java:64) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:324) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488) at com.isomorphic.servlet.DataSourceLoader.processRequest(DataSourceLoader.java:89) at com.isomorphic.servlet.DataSourceLoader.doGet(DataSourceLoader.java:64) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:324) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Code:
DataSource ID="masterDetail_order" serverType="hibernate" tableName="masterDetail_order" beanClassName="com.smartgwt.sample.server.Order" testFileName="/ds/test_data/masterDetail_order.data.xml" > <fields> <field name="orderId" type="sequence" primaryKey="true" canEdit="false" /> <field name="customerName" type="text" /> <field name="orderDate" type="date" /> <field name="items" title= "Order Items" multiple="true" type="masterDetail_orderItemHB" javaClass="com.smartgwt.sample.server.OrderItem" /> <field name="trackingNumber" type="integer" /> </fields> </DataSource>
Code:
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="connection.driver_class">org.hsqldb.jdbcDriver</property> <property name="connection.url">jdbc:hsqldb:hsql://localhost/isomorphic</property> <!-- disable native hibernate connection pooling: it's not recommended for production use and can't handle connection re-establishment. The recommended approach is to obtain database connections from the container and have the container manage the pool --> <property name="connection.pool_size">0</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.HSQLDialect</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">org.hibernate.transaction.JDBCTransactionFactory</property> <!-- Release database connections when session are closed. Otherwise, if the DB agressively cuts connections, we could end up trying to use a broken connection. --> <property name="hibernate.connection.release_mode">on_close</property> <!-- don't use a data cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Pretty-print logged sql --> <property name="format_sql">true</property> <property name="show_sql">true</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">update</property> <mapping class="com.smartgwt.sample.server.Order"/> <mapping class="com.smartgwt.sample.server.OrderItem"/> </session-factory> </hibernate-configuration>
Code:
package com.smartgwt.sample.server; //---------------------------------------------------------------------- // Master-Detail load and save example (Hibernate) // // Order Bean - to be managed by Hibernate //---------------------------------------------------------------------- import java.io.Serializable; import java.util.Date; import java.util.Set; import javax.persistence.*; @Entity @Table(name="orders") public class Order implements Serializable { private static final long serialVersionUID = -2722967662983593881L; @Id @GeneratedValue(strategy=GenerationType.AUTO) Long orderID; String customerName; Date orderDate; Long trackingNumber; @OneToMany @JoinColumn(name="orderId",nullable=true) Set<OrderItem> items; public Long getOrderID() { return orderID; } public void setOrderID(Long orderID) { this.orderID = orderID; } public String getCustomerName() { return customerName; } public void setCustomerName(String customerName) { this.customerName = customerName; } public Date getOrderDate() { return orderDate; } public void setOrderDate(Date orderDate) { this.orderDate = orderDate; } public Long getTrackingNumber() { return trackingNumber; } public void setTrackingNumber(Long trackingNumber) { this.trackingNumber = trackingNumber; } public Set<OrderItem> getItems() { return items; } public void setItems(Set<OrderItem> items) { this.items = items; } }
applicationContext.xml
Code:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <!-- Transaction manager for supplyItemDMI --> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="hibernateSessionFactory"/> </bean> <!-- Hibernate SessionFactory --> <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"/> <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" /> </bean> </beans>
Comment