Hi,
Here is a simple schema:
client tier<--->ds.xml<--->server tier<--->hbm.xml<--->DB
In most extreme case you can define POJOs and mapping (ds.xml) for client-server communications; POJO's and mapping (hbm.xml) for server-DB communications; some logic on the server side which transfer data client-POJO<--->server-POJO.
Usually you reuse POJOs (client-POJO==server-POJO). Mapping files are still necessary because presentation can differ from persistence:
in hbm.xml:
id
nickName
firstName
lastName
in ds.xml (firstName and lastName will not be visible on the client)
id
nickName
formattedName (calculated field: firstName + lastName; declared in POJO but transient to Hibernate)
When you need same fields for presentation and persistence you can reuse POJO and can reuse Hibernate mapped fields (from hbm.xml) by specifying autoDeriveSchema="true" (in ds.xml).
Specifying autoDeriveSchema in ds.xml will on fly copy field definitions from Hibernate configuration.
Alius
Announcement
Collapse
No announcement yet.
X
-
Hi,
thank you, that's great.
I still don't understand this hibernate datasource: do I need to put there autoderriveschema if I want to reuse hibernate mapping from hbm.xml files? Is it possible, or the datasource is just using hibernate connection without field mapping? It seems to me, that I would copy field definition from *hbml.xml into *ds.xml and have them in two places.
Leave a comment:
-
Hi,
I've just committed changes. It allows continuing execution if Spring configured Hibernate session factory is found but failed to create from .cfg.xml file.
You will be able to pick up these changes with next nightly build.
Regards,
Alius
Leave a comment:
-
Hi,
Just to clarify - could you check your log for messages (just before your specified exception):
Could not find expected class when attempting to obtain Hibernate config from Spring - is Spring correctly installed and configured?Attempted lookup of Hibernate sessionFactory via Spring bean mySessionFactory failed. The returned object was not an instance of LocalSessionFactoryBean
Regards,
Alius
Leave a comment:
-
Well, I 've got the error when it is missing. Do I need to switch on something in configuration files to not have it as an error? Because application ends in this point. also when I have it empty it is not reading configuration in the bean.
Code:=== 2011-02-17 11:32:27,103 [80-3] ERROR DataSourceLoader - Exception while attempting to load a DataSource java.io.FileNotFoundException: C:\dev\apache-tomcat-6.0.29\webapps\wep\WEB-INF\classes\hibernate.cfg.xml (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:106) at com.isomorphic.io.ISCFile.getInputStream(ISCFile.java:346) 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) ...
Leave a comment:
-
We'll look for the file regardless because some people use both Spring and .cfg.xml concurrently. It is not an error for it to be absent (or you can have it present but empty).
Leave a comment:
-
Thank you for your fast answer.
I've not described my situation properly:
I have definition of the hibernatesessionfactory springbean where there are all the mappings specified. So I have no annotated classes but *.hbm.xml files there, from which the classes are generated. I put autoderive and beanclassname into datasource definition as I wanted to bind it somehow with that already existing mapping.
Do I understand correctly that all is needed is to have following lines in the file server.properties:
Code:hibernate.config.lookupStyle: spring hibernate.config.bean: mySessionFactory
Code:<DataSource ID="user" serverType="hibernate" beanClassName="org.company.bo.User" />
Leave a comment:
-
You're close, just remove your setting of schemaBean. You would generally only use this property if you were *not* using Hibernate. For Hibernate, the combination of beanClassName and autoDeriveSchema already causes auto-derivation of fields (from org.company.bo.User in your case).
Leave a comment:
-
Hibernate datasource
How do you define hibernate datasource? I have existing application with spring and hibernate. Datasource is defined as:
Code:<DataSource ID="user" serverType="hibernate" autoDeriveSchema="true" schemaBean="hibernateSessionFactoryBean" beanClassName="org.company.bo.User" />
Code:WARN HibernateDataSource - Declared schemaBean 'hibernateSessionFactoryBean' was not found among existing Hibernate mappi ngs. Falling back to examining the JDBC metadata.
Code:java.lang.Exception: table DBTABLE does not exist or contains no columns.
smartGWT version: 2.4.2011-01-06-EVALTags: None
Leave a comment: