Mapping String to NVARCHAR2
alex1234567890 Sep 6, 2006 7:43 AMHi,
I have entities with Memebers of type String. I try to persist these entities in a Oracle database.
persistence.xml
<?xml version="1.0" encoding="UTF-8"?> <persistence> <persistence-unit name="test"> <jta-data-source>java:/testDS</jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/> <property name="hibernate.hbm2ddl.auto" value="validate"/> <property name="hibernate.cache.provider_class" value="org.jboss.ejb3.entity.TreeCacheProviderHook"/> <property name="hibernate.treecache.mbean.object_name" value="jboss.cache:service=EJB3EntityTreeCache"/> <property name="hibernate.cache.use_query_cache" value="true" /> <property name="hibernate.show_sql" value="true" /> <property name="jboss.entity.manager.jndi.name" value="java:/EntityManager/classes"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/managedEntityFactories/classes"/> </properties> </persistence-unit> </persistence>
The tables in the database are already created. At the start of the JBoss I get the following Exception:
org.hibernate.HibernateException: Wrong column type: sName, expected: varchar2(255 char)
The colum sName has the type nvarchar2 to support unicode. I tried to use a jbosscmp-jdbc.xml to create my own type mapping:
<jbosscmp-jdbc> <defaults> <datasource>java:/testDS</datasource> <datasource-mapping>mymapping</datasource-mapping> </defaults> <type-mappings> <type-mapping> <name>mymapping</name> ... <mapping> <java-type>java.lang.String</java-type> <jdbc-type>VARCHAR</jdbc-type> <sql-type>NVARCHAR2(255)</sql-type> </mapping> </type-mapping> </type-mappings> </jbosscmp-jdbc>
In my datasource configuration I use this type mapping:
<datasources> <local-tx-datasource> <jndi-name>testDS</jndi-name> <connection-url>...</connection-url> <driver-class>oracle.jdbc.driver.OracleDriver</driver-class> <!-- The login and password --> <user-name>...</user-name> <password>...</password> <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name> <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) --> <metadata> <type-mapping>mymapping</type-mapping> </metadata> <max-pool-size>50</max-pool-size> </local-tx-datasource> </datasources>
Why Hybernate don't map java.util.String to NVARCHAR2 with these configuration?
Waht is to do to map String to NVARCHAR2?