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?
Related
I am new to hibernate, developing my first simple program, I got exception of missing Event.hbm.xml file.
I added it, copying code from the net, the I got Person.hbm.xml missing.
I added it then PhoneNumber.hbm.xml missing.
Am I missing some sort of library.
I am working in eclipse.
Assuming there is hibernate.cfg.xml file used for hibernate configuration, you should check for <mapping resource>. File(s) (.hbm.xml) mentioned with <mapping resource> is must be present in that package if it's not found then it will throw the exception.
So either remove <mapping resource> entry for files that are not preset or add the files.
I am facing this weird issue while opening hbm file. I am using hibernate3.jar. I also verified that there is only one hibernate3.jar in classpath and it contains hibernate mapping dtd file.
I tried to put code and exception here but StackOverFlow engine continuously throwing some error.
Code and exception is given at [link] https://forum.hibernate.org/viewtopic.php?f=1&t=1029004.
I also tried by specifying docBuilder.setEntityResolver(new DTDEntityResolver());
I was running it via Apache Ant and behind proxy.
Any pointers will be appreciated.
Thanks,
Setting proxy values as export
ANT_OPTS="-Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080"
didn't work. So, I set the proxy values in Ant's build file as given in ant documentation and it worked.
<property name="proxy.port" value="80"/>
<property name="proxy.user" value=""/>
<property name="proxy.pass" value=""/>
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>
I'm working in a Java Web Project.
I need to change the folder of the files "jdbc.properties" and "log4j.properties" depending of the environment, because testing, demo and release have diferent values for those files.
I have this folders and subfolders:
c:\myProject\conf\dev
c:\myProject\conf\test
c:\myProject\conf\demo
I need to put diferent jdbc.properties and log4j.properties files in each of those folders
c:\myProject\conf\dev\log4j.properties
c:\myProject\conf\dev\jdbc.properties
c:\myProject\conf\test\log4j.properties
c:\myProject\conf\test\jdbc.properties
c:\myProject\conf\demo\log4j.properties
c:\myProject\conf\demo\jdbc.properties
The three project are in the same Server and in the same Apache (It is a Web Project)
First i made some changes to use a windows system variable to get the parent folder (c:\myProject). To do that, i made this on Spring appContext file:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>file:${PARENT_FOLDER}/conf/dev/jdbc.properties</value>
</property>
</bean>
"PARENT_FOLDER" is defined on Windows environment variables/system variable
Those changes works OK.
But, as you can see, I always loking for file on "/conf/dev"
I need to make dynamic the "dev" part of the path.
I Can't use Windows environment variables/system variable because the 3 environments are deployed on the same Server.
I'm trying to use a "property" (using ) on web.xml, but I don't know how to find the property in my Spring appContext file.
I definy the property like this:
<env-entry>
<env-entry-name>ENVIRONMENT</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>Dev</env-entry-value>
</env-entry>
But I don't know how to access "ENVIRONMENT" property on Spring
I don't know what to do. I a little desperate
Can someone help me?
Thanks and sorry for my poor english
Have you considered using JNDI?
With JNDI you will define the db connection properties inside tomcat itself. This way your spring configuration is independent of the environment and you can deploy the same war on all environments. See also this.
If you need to run it locally that you can always use the 'new' spring environment profiles feature.
Other option (if JNDI is not an option and assuming you use maven) is the maven replacer plugin where you will generate the db.properties at build time.