org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast to org.postgresql.PGConnection - blob

Within a Stateless bean I m trying to insert into a table which has an OID field. Please find the snippet below:
DataSource dataSource = (DataSource) context.lookup(JNDI_NAME);
Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(sql.toString());
byte[] streamOutput = responseData.getBytes();
LargeObjectManager largeObjectManager = ((org.postgresql.PGConnection)connection).getLargeObjectAPI();
long oid = largeObjectManager.createLO(LargeObjectManager.READ | LargeObjectManager.WRITE);
LargeObject largeObject = largeObjectManager.open(oid, LargeObjectManager.WRITE);
largeObject.write(streamOutput);
largeObject.close();
I m getting the below exception in LargeObjectManager largeObjectManager = ((org.postgresql.PGConnection)connection).getLargeObjectAPI();
org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast to org.postgresql.PGConnection : java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast to org.postgresql.PGConnection
The Stateless bean's TransactionManagementType is set to Container.
I m using Postgresql 9.1 and JBoss AS7.1
Can somebody please help me??

Generally this means you have two different libraries on your class path. Make sure you haven't included a PostgreSQL library in your deployment.

Related

ignite query cache with value as list of objects

I am using ignite cache with key as String and value as Collection of objects (similar type) say List.
Now i would like to query on the students stored in cache let's say 5 top scored students.
defined the configuration as below
CacheConfiguration<String, List<Student>> cfg = new CacheConfiguration<String, List<Student>>("students");
ignite = Ignition.start("/usr/localc/ignite/examples/config/example-ignite.xml");
cfg.setIndexedTypes(String.class, List.class);
Now I fired a query like
SqlFieldsQuery qry = new SqlFieldsQuery("select count(*) from Person");
Then got exception like
Exception in thread "main" java.lang.AbstractMethodError: org.apache.ignite.internal.processors.query.h2.opt.GridH2Table$ScanIndex.getCost(Lorg/h2/engine/Session;[I[Lorg/h2/table/TableFilter;ILorg/h2/result/SortOrder;Ljava/util/HashSet;)D
at org.h2.table.TableFilter.getBestPlanItem(TableFilter.java:203)
at org.h2.table.Plan.calculateCost(Plan.java:123)
at org.h2.command.dml.Optimizer.testPlan(Optimizer.java:183)
at org.h2.command.dml.Optimizer.calculateBestPlan(Optimizer.java:79)
at org.h2.command.dml.Optimizer.optimize(Optimizer.java:242)
at org.h2.command.dml.Select.preparePlan(Select.java:1014)
at org.h2.command.dml.Select.prepare(Select.java:878)
at org.h2.command.Parser.prepareCommand(Parser.java:259)
at org.h2.engine.Session.prepareLocal(Session.java:560)
at org.h2.engine.Session.prepareCommand(Session.java:501)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1202)
at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:73)
at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:290)
at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.prepareStatement(IgniteH2Indexing.java:406)
at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryTwoStep(IgniteH2Indexing.java:1121)
at org.apache.ignite.internal.processors.query.GridQueryProcessor$2.applyx(GridQueryProcessor.java:732)
at org.apache.ignite.internal.processors.query.GridQueryProcessor$2.applyx(GridQueryProcessor.java:730)
at org.apache.ignite.internal.util.lang.IgniteOutClosureX.apply(IgniteOutClosureX.java:36)
at org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuery(GridQueryProcessor.java:1666)
at org.apache.ignite.internal.processors.query.GridQueryProcessor.queryTwoStep(GridQueryProcessor.java:730)
at org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:700)
at com.tcs.enm.processor.Main.main(Main.java:47)
Can any one help me how to query ???
To execute such query you should store each Student as a separate entry. Student class should have all the annotations defining fields and indexes and the cache configuration should look like this:
cfg.setIndexedTypes(String.class, Student.class);
For more details refer to this documentation: https://apacheignite.readme.io/docs/sql-queries
For anyone in the future who has this issue, this error message is likely due to using an incorrect version of H2.
http://apache-ignite-users.70518.x6.nabble.com/Exception-while-trying-to-access-cache-via-JDBC-API-td8648.html#a8651
If you're using Ignite 1.7, you need h2database 1.4.191.
Note that h2database 1.4.192 WILL give you the exception in the question because there are some changes in 192 which Ignite wasn't made to handle
I went through my packages and changed the H2 version to 1.4.191 and it fixed my problems.

EFUtilities with EFProfiler running

I was wondering if there was a way to get EFUtilities running at the same time EFProfiler is running.
I appreciate the profiler would not show the bulk insert due to it being done outside the confines of DBContext. At the moment, I cannot run batch jobs as the profiler has the connection wrapped. It Runs fine when not enabled
The exception I am getting is thus:
A first chance exception of type 'System.InvalidOperationException'
occurred in EntityFramework.Utilities.dll
Additional information: No provider supporting the InsertAll operation
for this datasource was found
The inner exception is null.
This is because EFUtilities automatically finds the correct provider. But when the connection is wrapped this is no longer possible.
InsertAll looks like this.
public void InsertAll<TEntity>(IEnumerable<TEntity> items, DbConnection connection = null, int? batchSize = null)
To use the SqlProvider (which is actually the only provider out of the box) you can create a new SqlConnection() and pass that to insert all.
So basically you would need to do this:
using (var db = new YourContext())
using (var con = new SqlConnection(YourConnectionString))
{
EFBatchOperation.For(db, db.PartialTestClass1).InsertAll(partials, con);
}
Now, maybe you are doing more and want both parts to run under the same transaction. In that case you can wrap that code block in a TransactionScope.

Casting error with a native SQL query JPA Eclipse Link

I'm working with JPA implemented with EclipseLink. I need to do a native SQL query about my MRAEmpleado entity.
This is my code:
private List<MRAProyecto> ordenarProyectos (){
Query q = em.createNativeQuery("Select *From MRAProyecto ORDER BY PROY_ID");
return (List<MRAProyecto>)q.getResultList();
}
List<MRAProyecto> consultaProyectos = startup.ordenarProyectos();
System.out.println("Lista de proyectos ordenados por su identificador");
for (MRAProyecto proyecto:(List<MRAProyecto>)consultaProyectos){
System.out.println(proyecto.toString());
}
but This error is launched when I execute my application:
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to entity.MRAProyecto
at Startup.main(Startup.java:39)
I have tried with all casting posibilities, but the cast error doesn't dissapear.
Use the following call to do the parse.
Query createNativeQuery(java.lang.String sqlString, java.lang.Class resultClass)
Create an instance of Query for executing a native SQL query.
http://docs.oracle.com/javaee/6/api/javax/persistence/EntityManager.html#createNativeQuery%28java.lang.String,%20java.lang.Class%29
You need to define in resultSetClass the entitiy you want to retrieve

java.sql.SQLException: ORA-03115: unsupported network datatype or representation

I'm Using Oracle 11g database. When i try to access data from db it was showing the error java.sql.SQLException: ORA-03115: unsupported network datatype or representation. I'm not understanding what this error means..
my code is :
String uname,pass;
ResultSet rs = null;
response.setContentType("text/html");
PrintWriter out=response.getWriter();
try
{
uname=request.getParameter("uname");
pass=request.getParameter("pass");
Connection con=prepareConnection();
String Query="select uname from passmanager where pass=?";
PreparedStatement ps=con.prepareStatement(Query);
ps.setString(1,pass);
rs=ps.executeQuery(Query);
if (rs.next() && uname.equalsIgnoreCase(rs.getString("uname")) || uname.equalsIgnoreCase(rs.getString("email"))) {
HttpSession session = request.getSession(true);
session.setAttribute("uname", rs.getString(1));
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context
.getRequestDispatcher("/profile");
dispatcher.forward(request, response);
}
Any one help me to solve this problem..
Instead of:
rs = ps.executeQuery(Query);
you should execute:
rs = ps.executeQuery();
Otherwise, you unprepare your statement and lose all parameters because you assign it a new SQL statement (even though it's the same).
This error appears when you try to get a field by name ( rs.getString("uname") in your case) which is not in the resultset.
And like igr said, you are trying to get the email field ( with rs.getString("email") ) and it's not in the query, so this is your error.
I found this conversation because I was getting the same error in an application when I was trying to get a field with an whitespace at the end of the string ( rs.getString("uname ") instead of rs.getString("uname" ).
And I just fix it using the correct name for the field I was getting from the query.
I hope it is useful! ;)
Add email column
select uname, email from passmanager where pass=?

Unity Exception resolving type that is correctly mapped. Why?

I'm getting this error trying to implement the sample WCF Dependency Injection with Unity.
Resolution of the dependency failed, type = "SampleServiceUsingUnity.ExampleService", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The current type, ExampleServiceUsingUnity.IExampleManager, is an interface and cannot be constructed. Are you missing a type mapping?
-----------------------------------------------
At the time of the exception, the container was:
Resolving SampleServiceUsingUnity.ExampleService,(none)
Resolving parameter "exampleManager" of constructor SampleServiceUsingUnity.ExampleService(SampleServiceUsingUnity.IExampleManager exampleManager)
Resolving SampleServiceUsingUnity.IExampleManager,(none)
Problem is, I've tried to even explicitly map the types...and when I debug the code I go to the immediate window and look at the registrations. See below:
**DependencyFactory.Container.Registrations.ToList()[2]**
{Microsoft.Practices.Unity.ContainerRegistration}
buildKey: {Build Key[SampleServiceUsingUnity.IExampleRepository, null]}
LifetimeManager: {Microsoft.Practices.Unity.ContainerControlledLifetimeManager}
LifetimeManagerType: {Name = "ContainerControlledLifetimeManager" FullName = "Microsoft.Practices.Unity.ContainerControlledLifetimeManager"}
MappedToType: {Name = "ExampleRepository" FullName = "SampleServiceUsingUnity.ExampleRepository"}
Name: null
RegisteredType: {Name = "IExampleRepository" FullName = "SampleServiceUsingUnity.IExampleRepository"}
So the mapping looks right, but when the service attempts to instantiate that interface using Resolve, I get the error.
The code examples are supplied at:
http://msdn.microsoft.com/en-us/library/hh323725.aspx
The exception is talking about IExampleManager while the registrations are about IExampleRepository. Any chance you are missing the mapping for the manager and instead supplied one for the repository?