I am using classes that are a in referenced project as the mapping for hibernate project - I am able to use the classes in Java code but cannot refer to the classes in the hibernate config file. I get WARN: HHH000183: no persistent classes found for query class
so in the hibernate mapping config file I am using:
...
<mapping package="com.me.my.proj.oracle"/>
<mapping class="com.me.my.proj.oracle.WDI_HBD_PSNG_SMRY"/>
</session-factory> ###end of hibernate config file###
Is it possible to reference a class in a reference project using hibernate?
Your referenced project (Java) is added as JAR file in your current project's classpath. I think you need to use mappingJarLocation with location as your ReferenceProjectName.jar.
<property name="mappingJarLocations" value="file:**/ReferenceProjectName.jar"/>
Related
I am trying to create a sample project to demonstrate the use of grails 5 with gorm 7.
Here I am trying to map hibernate entities using hibernate.cfg.xml file. The hibernate.cfg.xml file is placed under grails-app/conf/ diectory.
The hibernate entity java classes are annotated with javax.persistence.Entity annotation.
But these entity classes are not mapped by grails and performing any save, list etc operations on these entities throws org.hibernate.MappingException: Unknown entity exception.
Please find the sample project here.
Can you try moving the hibernate.cfg file to hibernate folder or refer the path in application.yml https://docs.grails.org/3.0.x/guide/hibernate.html
I want to get rid of xml table mappings from my hibernate.cfg and replace them with references to classes themselves.
Here is what is used to have in my hibernate.cfg and what i'm replacing it with..
<mapping class="com.eugene.repository.mappings.Users"/>
<!--<mapping resource="/mappings/Users.hbm.xml"/>-->
I can do that and then run tests from my local box and everything works well,
but when i create war file and upload it to tomcat, it cant resolve mappings..
What am i missing?
I am developping a standalone application with hibernate, using the following stucture for my project :
This is how I told hibernate(yes, I'm chatting with Hibernate) where to find the hibernate.cfg.xml file :
File hibernateConfigurationFile = new File("..\\resources\\hibernate.cfg.xml");
...
Configuration().configure(hibernateConfigurationFile).buildSessionFactory();
This is how I told hibernate where to find the Event.hbm.xml file :
<mapping resource="../resources/test/Event.hbm.xml"/>
I also tried :
<mapping resource="test/Event.hbm.xml"/>
But when I compile it, I have the following error :
Initial SessionFactory creation failed.org.hibernate.MappingNotFoundException: resource: test/Event.hbm.xml not found
I understand it is because I indicated the wrong mapping file path in my hibernate.cfg.xml file. So I moved my Event.hbm.xml file, and the structure of my project is now :
And all works fine.
My problem is that I would like to keep my Event.hbm.xml in the resource\test directory. How can I indicate that in my hibernate.cfg.xml file? I tried relative paths, but it doesn't work. I read hibernate documentation, but found nothing. Any suggest?
You can try programmatic way of building hibernate configuration and can say
SessionFactory sf = new Configuration()
.addFile("yourpath/Event.hbm.xml")
instead of declaring mapping resource in hibernate.cfg.xml
see this method
I was facing the same problem
I used this
<mapping file=".\hibernate\groupResult.hbm.xml" />
Means there is an attribute file in mapping
.\hibernate\groupResult.hbm.xml
will be in your project folder in that hibernate folder in that groupResult.hbm.xml
Hope this will help you!
Cheers!
I am trying to use Hibernate 3.2.5 with Play framework 1.2.5
In Hibernate I am having two files:
1) cfg.xml file (containing the db config details along with some additional properties
2) hbm.xml file (containing the mapping between the java bean and the db table
For getting connected to the oracle 10g db, I am providing the db details in the application.config files like this and the connection is successful also when I start the server:
db.url=jdbc:oracle:thin:#localhost:1521/orcl
db.driver=oracle.jdbc.OracleDriver
db.user=system
db.pass=tiger
I want to know Where will I place the hbm.xml file (for mapping details) and the cfg.xml file for the remaining properties other than db connecion details?
Please let me know about this.
Regards,
Starting from the root directory of your application:
the hibernate.cfg.xml must be placed inside the app directory
the mapping files (the hbm files) where your models classes are defined, usually inside the app/models/ directory
Inside your hibernate.cfg.xml the mapping attributes should be something like:
<mapping class="models.yourHmbFile1"/>
<mapping class="models.yourHmbFile2"/>
Btw, I find easy to use the hibernate annotations instead of the hbm - xml mapping. Easier to write and to mantain.
If you prefer to annotate your model classes, you can delete the hbm files and directly map your annotated classes in your hibernate.cfg.xml.
In the application.conf you've to specify the data you have already added:
db.url=jdbc:oracle:thin:#localhost:1521/orcl
db.driver=oracle.jdbc.OracleDriver
db.user=system
db.pass=tiger
Also in the hibernate.cfg.xml you need to specify the connection data:
<property name="hibernate.dialect">...</property>
<property name="hibernate.connection.driver_class">...</property>
<property name="hibernate.connection.url">...</property>
<property name="hibernate.connection.username">...</property>
<property name="hibernate.connection.password">...</property>
Most or all the core hibernate configuration properties can be specified in a startup properties file, as an alternative to specifying mappings in hibernate.cfg.xml.
Is there an easy way to specify mappings of annotated classes in a properties file?
You can map annotated classes like this in the hibernate.cfg.xml configuration:
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
...
<mapping class="com.annotated.classes.EntityOne"/>
</session-factory>
Similar configuration can be written using a properties file i.e. hibernate.properties
hibernate.connection.driver_class = com.mysql.jdbc.Driver
hibernate.mapping = ???
What I haven't figured out is how to specify the mapping of annotated classes (entities) using the properties configuration, if this is possible.
I don't think there is any way to specify entities in the properties file.
I suppose you could create your own custom initialization code using Configuration to accomplish what you are looking for. The problem with using a properties file, though, is that you cannot specify a property with a list of values unless you identify a way to split the value into a list. You would then need to write code that parses the value accordingly.