leostiw
leostiw

Reputation: 1155

Select value from a table that is not mapped

Is it possible to select a value from a table that is not mapped ?

Here an example:

This is my payscale table:

enter image description here

I want to load the price for WARE like 'ALLE' and desstination 'AUT'. However, I only need the "wert" value, not the whole object. I also don't need this table to be mapped in my project, I only need to get the value.

I tried following:

TypedQuery<Double> q = em.createQuery(
                "SELECT wert FROM TVTARIF WHERE destination like '?1' and ware like '?2'",Double.class)
                .setParameter(1, transportZertifikat.getTransportGebiet())
                .setParameter(2, "ALLE");
System.out.println(q.getSingleResult());

But I get following error:

 org.hibernate.hql.internal.ast.QuerySyntaxException: TVTARIF is not mapped [SELECT wert FROM TVTARIF WHERE destination like '?1' and ware like '?2']

Upvotes: 0

Views: 263

Answers (1)

trogdor
trogdor

Reputation: 1656

Try with createNativeQuery instead of createQuery. It receives a plain SQL query and your tables do not have to be mapped.

Upvotes: 2

Related Questions