I have a project using Hibernate and external XML mapping files. I switched from MySQL to Oracle. Some of my fields have the name 'date', which is okay in MySQL but not in
Oracle. It does not like
<property name="date" column="date" type="string" />
so I changed it to
<property name="sdate" column="sdate" type="string" />
When I re-rerun the code to generate the schema, it is still following the old version of the mapping file and not taking into account the new changes. I have even created a similar but different xml file and pointed my Hibernate config to this new file and it has the same problem.
Does anyone know why it could be following the old version of my mapping file and refusing to follow my updates?
Related
i deploy oracle database and create 2 schema
core
msg
c_user table is in core and i wanna create m_message table in msg schema.
my application structure is:
Core-Project that is a independent dependency and includes in other projects and User.hbm.xml is there in it.
i add Core-Project into pom.xml of Message-Project. Message-Project has Message.hbm.xml.
i use hibernate 4 and my hibernate mapping file is somethings like below. when i start my application (Message-Project), i wanna to m_message created foreign key with c_user table that is in core schema but hibernate generated DDL is wrong. i think hibernate cannot set default_schema properties in User.hbm.xml that is not schema attribute!
Note. i don't wanna to add a schema attribute in User.hbm.xml because Core-Project added into more than 10 projects.
Message.hbm.xml in message-project
<class name="org.message.model.Message" table="m_message" schema="msg">
<many-to-one name="sender" column="sender_Id" entity-name="org.core.model.User" not-null="true" />
...
</class>
User.hbm.xml in core-project
<class name="org.core.model.User" table="c_user">
...
</class>
oracle-hibernate.properties
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.url=jdbc:oracle:thin:#localhost:1521:HRM
hibernate.connection.username=msg
hibernate.connection.password=msg
hibernate.connection.internal_logon=normal
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
hibernate.hbm2ddl_auto=update
hibernate.default_schema=core
hibernate XML configuration file
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource_" ref="dataSource_" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.default_schema"> ${hibernate.default_schema}</prop>
...
</props>
</property>
</bean>
hibernate generated DDL for foreign key in something like below:
alter table msg.m_message add constraint FK_filpe81gwdf3f6oqn54d5ybh3
foreign key (sender_Id) references msg.c_user
why msg.c_user? why hibernate cannot set default_schema for tables that haven't schema attribute?
i think the order of using default_schema for generate foreign key is :
1) using schema of User.hbm.xml and then if not exists
2) using schema of Message.hbm.xml and then if not exists
3) using the default_schema of oracle-hibernate.properties
how can i change this order? thanks a lot...
Most likely this is a bug. However, even if it is, it will not be fixed in Hibernate 4.
If you can replicate it with Hibernate 5.2, then you should open a new Jira issue, and the issue will be fixed.
However, relying on the HBM2DDL for your production database is much more of an issue. HBM2DDL is good for testing and prototyping, not for production environments. You should use Flyway to manage your database schema.
Good morning,
I've been working on a project where I'm supposed to:
upgrade the application from JRockit 1.6 to Java 7
upgrade the application to run in a WebLogic 10.3.5 environment to run in a WebLogic 12 environment
I'm sure this doesn't help but I'm new to the Java/Spring/WebLogic world.
I was able to upgrade from JRockit 1.6 to Java 7 but when it comes to the WebLogic part, I've been having issues starting the application.
Every time I do, I get the following error
org.jibx.runtime.JiBXException: Missing required attribute "a" (line 1, col 71)
at org.jibx.runtime.impl.UnmarshallingContext.attributeText(UnmarshallingContext.java:975)
at com.mydomain.JiBX_rule_def_bindingMungeAdapter.JiBX_rule_def_binding_unmarshalAttr_1_0()
at com.mydomain.JiBX_rule_def_bindingMutableRuleDefinition_access.unmarshal()
at org.jibx.runtime.impl.UnmarshallingContext.unmarshalElement(UnmarshallingContext.java:2757)
at org.jibx.runtime.impl.UnmarshallingContext.unmarshalDocument(UnmarshallingContext.java:2900)
and have been trying to debug it for a while now. What's really weird is that when I take out the code from a Spring/WebLogic environment and execute it, it works fine (ie, unmarshalls the data).
When it was in the WebLogic 10.3.5 environment w/ JRockit 1.6 and JiBX 1.2.1 jars, I had zero issues.
Here's what I've tried
upgraded JiBX jars from 1.2.1 to 1.2.5
upgraded xpp3 jars to 1.1.3.4.O
upgraded Spring jars from 2.5.5 to 3.2.11
tried including a weblogic.xml file (didn't have one before) and try to used the
<preferred-web-inf>true</preferred-web-inf>
but no luck
tried including a weblogic-application.xml file and an APP-INF folder (didn't have one before) and tried to used the JiBX as my preffered class for unmarshalling
Here is some more information about the environment I'm working in
Non Maven Environment (had to upgrade .jars manually)
Used Java 1.7.0.45 and .71
WebLogic 1.2.1.2
Spring 3.2.11
JiBX 1.2.5
using MyEclipse Version: 2014 Build id: 12.0.0-20131202
no xsd file just a .xml binding file
<binding>
<mapping name="rule"
class="com.mydomain.MutableRuleDefinition">
<value name="a" field="a" style="attribute" />
<value name="b" field="b" style="attribute" />
<collection field="ruleElements">
<structure name="ruleElement"
type="com.mydomain.MutableRuleElement">
<value name="c" field="c" style="attribute" />
<value name="d" field="d" style="attribute" />
<collection field="values" item-type="java.lang.String"
usage="optional">
<value name="value" />
</collection>
</structure>
</collection>
</mapping>
</binding>
Here is the unmarshalling code:
private MutableRuleDefinition unmarshalXMLRuleDef(String _xmlRuleDef) {
MutableRuleDefinition mruleDef = null;
try {
IBindingFactory bfact = BindingDirectory
.getFactory(MutableRuleDefinition.class);
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
mruleDef = (MutableRuleDefinition) uctx.unmarshalDocument(
new ByteArrayInputStream(_xmlRuleDef.getBytes()), null);
} catch (JiBXException e) {
logger.error("Could not un-marshalling the XML rule definition:["
+ _xmlRuleDef + "]", e);
}
Apparently this was an issue back in JiBX 1.2.1 but was fixed in 1.2.2 :
https://www.mail-archive.com/jibx-users#lists.sourceforge.net/msg04200.html
Any help appreciated. Please let me know if you need more info...
Update #1
I have tried
<value name="a" field="a" style="attribute" usage=optional />
on all the attribute flags and the unmarshalling will work, however, these fields aren't optional so I can't use that as a fix.
Update #2
fwiw, here is an example that would come into be unmarshalled
<rule a="dataForA" b="dataForB">
<ruleElement c="dataForC1" d="dataForD1" />
<ruleElement c="dataForC2" d="dataForD2" />
<ruleElement c="dataForC3" d="dataForD3" />
<ruleElement c="dataForC4" d="dataForD3" />
</rule>
R Hanna,
I would suggest looking at the JiBX dependencies and making sure all of the Jars are the exact same version as the ones used by JiBX. We use some eclipse libraries that often conflict with web server jars.
Also, remember that JiBX is open source. You may want to step through the code and see what is causing JiBX to fail.
One more thing. I can't see your schema definition, but it is strange that the error seems to say that you are missing an attriburte. Are you sure the 'source' attribute is not required.
Good Luck!
Don Corley
JiBX contributor
R Hanna,
I got this resolved for me after using 1.2.5 version of jibx however i made sure all the related jars also updated to 1.2.5 and made sure there are no stale class files present in my war which were created by the previous jars that did the trick for me hope its helps you .
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 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 am using spring and hibernate. I have mapping locations specified as:
My folder structure is as follows:
src/main/resources
.
...hibernate
.
.....hibernate2
<property name="mappingLocations" value="classpath:hibernate/*.hbm.xml" />
above property is looking into only hibernate folder and is not looking into subfoders. how can i force to find hbm files in sub folders as well?
Insert a wildcard * as below
<property name="mappingLocations" value="classpath*:hibernate/**/*.hbm.xml" />