I try to create a hibernate mapping for an oracle database. The datebase is pretty old from before oracle 8 but is now on 10. Hibernate reverse engineering balks at a long raw column. This datatype is deprecated and should be converted to blob.
But this is not my database. If the customer refuses to convert how would a hibernate mapping look like ?
Try mapping it to byte[].
If you get java.sql.SQLException: Stream has already been closed, then try setting useFetchSizeWithLongColumn = true in the connection properties for the OJDBC driver. See the OracleDriver API
Related
While this mapping works in MySQL on saving objects:
#Id
private String id;
on Oracle it throws: ORA-01465: invalid hex number when I am saving my object.
This is how I create id: UUID.randomUUID().toString()
My app must support both MySQL 5 and Oracle 12. So I can add only some mysql / oracle specific adapters / extensions that could be easily turned off while switching from one db to another. I cannot change JPA entities code if that would mean binding them to specific database. It must work on both databases.
What could I do so that it wouldn't break the application while switching from one MySQL to Oracle ?
Just remove '-' from UUID.randomUUID().toString()
For example,
UUID.randomUUID().toString().replaceAll("-","")
What is the best way to store a a big String in SQL server Database.
I'm using varchar(8000) but I get this exception while persisting my Object using Hibernate :
>Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: String or binary data would be truncated.
Which version of SQL Server are you using? If the version is above 2005 Use VARCHAR(MAX). If the version is before 2005 you can use TEXT
When you want to store a very big string on SQL Server you can use:
varchar(max)
Well as I can see the tag of hibernate you need the tag of #Lob for storing super large objects.
Specifies that a persistent property or field should be persisted as a
large object to a database-supported large objec
Example:
#Lob #Basic(fetch=LAZY)
#Column(name="REPORT")
protected String report;
From Hibernate Docs.
I need to store base64 encoded document in Sybase database via stored procedure. I use JTDS driver.
As long as I am not trying to store my PDF document everything is fine. However as soon I attempt to path encoded string. I get the following error
java.sql.SQLException: Sybase does not support char parameters > 255
bytes.
Here is the code
conn.setAutoCommit(false);
cs = conn.prepareCall("{call sp_save_pdf (?,?,?,?)}");
cs.setString(++i, id);
cs.setString(++i, source);
cs.setString(++i, base64EncodedDocument);
cs.registerOutParameter(++i, java.sql.Types.INTEGER);
cs.execute();
When Sybase Developers execute this procedure but they use JConnect driver. Here is my question does JTDS driver not support usage of long strings and I need to use JConnect or do I miss something in my code?
Thanks
Issue was with JTDS driver as soon as I switched to JConnect driver everything began to work as expected.
I am having difficulty while reading from oracle database using hibernate. The column is of clob type and mapped class property is of String type. The database is Oracle 11G. I have tried to update my driver as suggested by some posts, But it was of no use. The problem is that All other columns(which are not clob) are read properly and the column which is clob is returned null besides it has data. Thanks in advance.
The query is :
select id,about_us,other_details,periodicity,active,createts,updatets from Details where id = ?
This above the HQL query where about_us and other_details are clob type in database. The java entity contains it as type String.
Rahul
I tried many solutions as suggested in different posts, It includes:
1) Updating odbc jar.
2) Using #lob on the porperty in hibernate mapping/entity.
Both of the above solutions did not work for me, Rather I used the hibernate function str(clob_property) to read it, It worked for me and I could get the property read.
Regards
Rahul
Have you tried something like this?
#Lob #Column(name = "long_text")
private String longText;
i have a java class persisting a string (>4k) into a database table into a CLOB field.
If the string is less than 4k then it works.
I have the field annotated using #Lob and initially I was getting an exception due to batching not supported for streams so I made the batch size 0 in the Hibernate config which is giving the exception:
Caused by: java.sql.SQLException: ORA-01460: unimplemented or unreasonable conversion requested
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:582)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1986)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1144)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2152)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2035)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2876)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2062)
... 36 more
I only get this issue when using the code from Grails. When I use the same code from a pure Java application then I don't get the issue. Both applications have the same hibernate config (except I need to set the batch size to 0 in Grails). Is the issue the difference in the Hibernate versions which is 3.2.6ga in Grails as far as I can see and 3.2.5ga for the java application. The Oracle driver is the same in both cases.
Any answers welcome.
Try with annotating the field with #Column(length = Integer.MAX_VALUE). This hibernate bug report mentions it helped in Derby.