When using OpenJPA to execute a select statement in in-memory database org.apache.derby, I encounter this error:
javax.ejb.EJBException: The bean encountered a non-application exception; nested exception is:
<openjpa-2.1.2-SNAPSHOT-r422266:1636464 fatal general error> org.apache.openjpa.persistence.PersistenceException: Syntax error: Encountered "optimize" at line 1, column 80. {SELECT t0.VERSION, t0.SOMEOTHER_COLUMN FROM MYTABLE t0 WHERE t0.MYTABLE_CODE = ? optimize for 1 row} [code=20000, state=42X01] FailedObject: UDA [org.apache.openjpa.util.StringId] [java.lang.String]
The OpenJPA client is embedded in a IBM WebSphere client: com.ibm.ws.jpa.thinclient-8.5.5.5.jar
Apparently OpenJPA adds the 'optimize for 1 row' part because it thinks it is dealing with DB2? How could this be possible? Is there any way I can turn off this feature explicitly?
I did find some explanation on the 'optimize for 1 row' postfix:
https://www.ibm.com/developerworks/community/blogs/22586cb0-8817-4d2c-ae74-0ddcc2a409bc/entry/optimize_for_1_row1?lang=en
Apparently OpenJPA adds the 'optimize for 1 row' part because it thinks it is dealing with DB2? How could this be possible? Is there any way I can turn off this feature explicitly?
With the information provided, I'm not sure why this is the case.
Fortunately, you can override this with the following property in your persistence.xml:
<property name="openjpa.jdbc.DBDictionary" value="derby"/>
Solved it. The application has derby configured, but it is using a data access service which in turn had db2 specified as the DB dictionary.
I am servicing on existing code and therefore could not find that setting right away. Thank you both for pointing me in the right direction.
Related
First of all, things were working perfectly in my previous laptop, when I shifted my code to the new laptop I am getting this error, Basically, I am calling finder method in my EJB and code of it was working fine as in EJB-jar it looks like this
<query>
<query-method>
<method-name>finduserrightsonform</method-name>
<method-params>
<method-param>java.lang.String</method-param>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql>select object(o) from UserRightsOnForm o where o.ser_groups_users_id=?1 and o.ser_form_id=?2</ejb-ql>
</query>
as both columns in DB are integers so as in my previous laptop Postgres auto-cast it's there, but what I am missing is strange.
so far as I tried
cast using cast(columnname as character varying) e.g. it also
through error
change method param to Integer it will not work as well, in fact,
stoped deployed the jar
changing the Postgress versions to the previous one.
casting like using ::smallint
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: integer = character varying
ERROR [stderr] (EJB default - 3) Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
its look like the environment maybe jar issue but what I am missing not catching it.
calling code:
sms.viewUserRightsOnFormImpl(userId, "validationForm", groupId);
defination:
Collection findUserRightOnForm(String user_id, String form_id) throws FinderException;
using
Jdevelper 11g
postgress 9.2
Jboss 6
EJB 2.1
Note: Tried all google links and stackover links almost wasted my 2 days.
I have just updated to Hibernate 3.6.5.Final from 3.3.0.GA and have run into a problem with a SQL formula call on an XML mapped property:
<property
name="endDate"
type="java.util.Date"
formula="TIMESTAMPADD(SECOND, (quantity*60*60), transactionDate)"
/>
I have changed nothing in the *.xml.hbm nor have I changed the database design. Where previously my endDate was nicely calculated I now get a MySQLSyntaxErrorException:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'this_.SECOND,(this_.quantity*60*60),this_.transactionDate) as formula0_0_ from t' at line 1
The problem is pretty obvious in that the this_.SECOND should be SECOND. It seems to me that Hibernate recognizes the TIMESTAMPADD as a formula but not the SECOND as a static passed parameter and thinks it thus must be a column in the table. I am unsure how to tell hibernate it should use SECOND as is.
I've tried registerFunction and registerKeyword on my Dialect but without any luck as these seem related to HQL function definitions and not native SQL which is used here in the formula.
Could anyone point me in the right direction or tell me what Hibernate does different between these versions and how I can fix it?
I just upgraded to Hibernate 4.1.2 and this same problem started coming back. The solution of [SECOND] no longer works and I had to register the keyword in my own custom Dialect. Like:
public class ExtendedMySQL5InnoDBDialect extends MySQL5InnoDBDialect {
public ExtendedMySQL5InnoDBDialect() {
super();
//make sure to register it in lowercase as uppercase does not work (took me 4 hours to realize)
registerKeyword("second");
}
}
I had the same type of problem in Sql Server - a similar solution might work. .
Here is what I found. .
https://forum.hibernate.org/viewtopic.php?p=2427791
So, try putting quotes around SECOND
<property
name="endDate"
type="java.util.Date"
formula="TIMESTAMPADD("SECOND", (quantity*60*60), transactionDate)"
/>
I am actually not sure how you would escape double quotes in this xml attribute, but I would try " first and if that doesn't work \"
I am trying to doing some SQL queries out of Oracle 11g and am having issues using ora:contains. I am using Spring's JDBC implementation and my code generates the sql statement:
select *
from view_name
where column_a = ?
and column_b = ?
and existsNode(xmltype(clob_column),
'record/name [ora:contains(text(), "name1") > 0]',
'xmlns:ora="http://xmlns.oralce.com/xdb"') = 1
I have removed the actual view / column names obviously, but when I copy that into sqlplus and substitute in random values, the select executes properly. When I try to run it in my DAO code I get this stack trace:
org.springframework.jdbc.UncatergorizedSQLException: PreparedStatementCallback;
uncatergorizedSQLException for SQL [the big select above]; SQL state [99999];
error code [31011];
ORA-31011: XML parsing failed.
ORA-19202: Error occured in XML processing
LPX-00607: Invalid reference: 'contains';nested exception is java.sql.SQLException:
ORA-31011: XML parsing failed
ORA-19202: Error occured in XML processing
LPX-00607: Invalid reference: 'contains'
(continues on like this for awhile....)
I think it is worth mentioning that I am using Maven and it is possible I am missing some dependency that is required for this. Sorry the post is so long, but I wanted to err on the side of too much info.
Thanks for taking the time to read this at least =)
-Windle
You appear to have a spelling mistake in your namespace declaration:
'xmlns:ora="http://xmlns.oralce.com/xdb"'
^^
If that really is a typo in your code (rather than just in your posting here) it can't hurt to fix it.
I wan to get the value of only one week. I am using the following JPA query:
SELECT a
FROM questions.dao.hibernate.Questions a
WHERE (a.posted_date-CURRENT_DATE)>= 7
But I am getting an error message like
org.hibernate.QueryException: could not resolve property: posted_date of: questions.dao.hibernate.Questions [SELECT a FROM questions.dao.hibernate.Questions a WHERE (a.posted_date-CURRENT_DATE)>=7]
Please help me.
Thanks
This sounds pretty self-explanatory to me. The class questions.dao.hibernate.Questions does not have a property called posted_date (it may have the property - that would be a strange naming convention though - but Hibernate doesn't know it).
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.