jpql

Why isn't my Entity Table mapped in JPA Hibernate?

久未见 提交于 2019-12-25 05:03:13
问题 I have an Entity: @Entity(name = "target_group") public class TargetGroup extends AbstractEntity { private String name; private String description; @ManyToMany(fetch = FetchType.LAZY) private List<Customer> customers = new ArrayList<>(); getter.setter... } And I have a code, to get a list about the groups with the stableId (which is in the Abstract Class): public TargetGroup getTargetGroupByStableId(String stableId) { TargetGroup tg = null; try { Query q = em.createQuery("SELECT tg FROM

JPA: How to persist column with SHA1 encryption ?

℡╲_俬逩灬. 提交于 2019-12-25 04:05:15
问题 I'm fairly new to JPA (and JPQL by extension). Hopefully, someone will be able to enlighten me with this problem. The query I'm trying to execute ... String query = "select u from user u where u.email = '" + userEmail + "' and u.password = sha1('"+ userPassword + "')"; List resultList = emf.createEntityManager().createQuery(query).getResultList(); And I'm getting the follwowing exception ... Caused by: Exception [EclipseLink-8025] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org

Persisting entity to database with JPA and autogenerated primary key identity

送分小仙女□ 提交于 2019-12-25 02:42:18
问题 I have a full Java EE web application with a presentation layer and a database. I'm using derby with glassfish 3.1 and JPA to handle persistence. I've created a Read ok but now I'm having troulbe doing a Create and persisting to the database. I think I'm close but something is not right with the way I'm trying to do the create. Here is my EAO code: /** * Session Bean implementation class XRSSeao */ @Stateless @LocalBean public class XRSSeao { @PersistenceContext EntityManager em; public

JPQL like expression requires int value

孤街浪徒 提交于 2019-12-25 02:21:24
问题 I'd like to search a requested value in my database using the entity manager createquery function. Whenever I executed my method, I got the following error message: llegalArgumentException: You have attempted to set a value of type class java.lang.String for parameter searchvalue with expected type of int from query string It says that a int value is required, but I think that every like expression requires a string value? Entity: public class Contract implements Serializable { private static

JPQL query not working after needed to adapt it

删除回忆录丶 提交于 2019-12-25 01:49:34
问题 I needed to change my JPQL query because it turned out that the last element of types ( contains 5 elements ) contains a wildcard so it can itself contain many elements basically. So now I changed the original query to only check if the TestcaseEntity contains 4 types instead of 5 and all the testcases coming out of this query I check now if they have any of the typesVariants ( previous 5 element ) which should deliver the resulting testcases. So now I wrote a subselect . What I found out now

Projection in JPQL with property of type list

让人想犯罪 __ 提交于 2019-12-25 00:57:44
问题 How I can made a select of a property of type list on JPQL? example: @Entity public class Person { @id private Long id; private String name; private String lastname; private String birthdate; @OneToMany private List<Phone> getPhones(); ... } @Entity public class Phone { @id private Long id; private String number; ... } And on repository I want a projection, so: public interface IPersonProjection { Long getId(); String getName(); List<Phone> phones(); } @Repository public interface

JPQL and list of tuples as parameter for SELECT IN statements

假如想象 提交于 2019-12-25 00:38:24
问题 Given the following table layout: CREATE TABLE things ( id BIGINT PRIMARY KEY NOT NULL, foo BIGINT NOT NULL, bar BIGINT NOT NULL ); An entity class (Kotlin): @Entity @Table(name = "things") class Thing( val foo: Long, val bar: Long ) : AbstractPersistable<Long>() And a repository: interface ThingRepository : JpaRepository<Thing, Long> { @Query("SELECT t FROM Thing t WHERE t.foo IN ?1") fun selectByFoos(foos: Iterable<Long>): Iterable<Thing> @Query("SELECT t FROM Thing t WHERE (t.foo, t.bar)

JPQL JOIN Queries

一笑奈何 提交于 2019-12-24 15:19:50
问题 I'm trying to make a very simple JPQL using a join but I'm having zero success. I want to get the most recent log in date of a user, given a user id. I am using Spring Data JPA + Hibernate. I have a MySQL database which contains the table Activity: @Table(name = "activity") @SuppressWarnings("serial") public class Activity implements Serializable { @Id @GeneratedValue private Long id; @Column(name = "date", insertable = true, nullable = false, updatable = false) @Temporal(TemporalType

Varchar to int typecasting in JPA 1.9

这一生的挚爱 提交于 2019-12-24 09:14:13
问题 I want to convert varchar to int in jpql. The field is varchar, but all the data will be in integer format only. My JPA library version is 1.9 I already used CAST and CONVERT methods, but it did not working. My query is: select SUM(Cast(model.wagonsRequired as INT)) from IptRailcargolines model where model.iptRailwayindent.id=7 or select SUM(CONVERT(INT, model.wagonsRequired)) from IptRailcargolines model where model.iptRailwayindent.id=7 and my java console error is: Caused by: Exception

Complex sql query and JPQL

强颜欢笑 提交于 2019-12-24 00:59:07
问题 How to change this complex sql statement into JPQL? select a.name, a.surname, b.street, c.location, c.location_desc from table1 join table2 on b.id = a.some_fk left join table3 d on d.id = a.id left join table4 c on c.some2_id = d.some2_fk where a.id = 400; If this is possible to present in the JPQL form? 回答1: Impossible to give a definitive answer without knowing the entities and their mapping, but the query would look like this: select a.name, a.surname, b.street, c.location, c.locationDesc