The Hibernate mapping is as follows:
Code:
<class name="com.thalasoft.learnintouch.core.domain.NavbarLanguage" table="navbar_language" dynamic-insert="true" dynamic-update="true">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native"><param name="sequence">sq_id_navbar_language</param></generator>
</id>
<version name="version" type="int">
<column name="version" not-null="true" />
</version>
<property name="languageCode" type="string">
<column name="language_code" length="2" />
</property>
<many-to-one name="navbar" class="com.thalasoft.learnintouch.core.domain.Navbar" cascade="all">
<column name="navbar_id" not-null="true" />
</many-to-one>
</class>
You can note that the id property is a java.lang.Integer type, and it builds and works fine against the MySql schema when building against MySql with the command: mvn clean install -Pmysql-test -Dtest=NavbarLanguageDaoTest
Note that the DAO method used against MySql is not the one displayed above but this one:
Code:
public List<NavbarLanguage> findWithNavbar(Navbar navbar) {
if (navbarLanguageCustomDao != null) {
return navbarLanguageCustomDao.findWithNavbar(navbar);
} else {
Criteria criteria = getSession().createCriteria(getPersistentClass());
criteria.add(Restrictions.eq("navbar", navbar)).addOrder(Order.asc("languageCode"));
return criteria.list();
}
}
Indeed, when running against MySql, there is no need to have a native sql DAO method, as the null values are ordered first by default on MySql, contrary to Oracle, which explains the native sql statement DAO method being used when building against Oracle.
So, only when I build against Oracle with the command: mvn clean install -Poracle-test -Dtest=NavbarLanguageDaoTest do I get the above exception.
Here are the schema tables definitions on both database servers.
For MySql:
Code:
CREATE TABLE `navbar_language` (
`id` int(10) unsigned NOT NULL auto_increment,
`version` int(10) unsigned NOT NULL,
`language_code` varchar(2) default NULL,
`navbar_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
KEY `navbar_id` (`navbar_id`),
KEY `navbar_id_2` (`navbar_id`,`language_code`),
CONSTRAINT `navbar_language_ibfk_1` FOREIGN KEY (`navbar_id`) REFERENCES `navbar` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
For Oracle:
Code:
create table navbar_language (
id number(10) not null,
version number(10) not null,
language_code varchar2(2),
navbar_id number(10) not null,
constraint navbar_language_pk primary key (id),
constraint navbar_language_fk1 foreign key (navbar_id) references navbar (id)
);
create sequence sq_id_navbar_language increment by 1 start with 1 nomaxvalue nocycle cache 10;
create or replace trigger tr_id_inc_navbar_language
before insert
on navbar_language
for each row
declare
begin
if (:new.id is null)
then
select sq_id_navbar_language.nextval into :new.id from dual;
end if;
end;