jpa

Persisting a new but identical entity with JPA reporting duplicate entry

I have a JPA project connected to a MySQL database where my entity object is mapped to a table with a constraint on 2 columns. That is: @Entity @Table(name = "my_entity") class MyEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "id") private Integer id; @Bas...

JPA mapping: Reusing entities in multiple relationships

Let's say I have: class Unit { private TextContainer source; private List<TextContainer> targets; } Can I annotate class TextContainer in such a way that it works within both relationships? TextContainer must be either source or target. ...

ClassCastException trying to cast retrieved JPA object to concrete class

I am not certain what I am doing wrong, but I have a class that has a class within it, so when I save the Skill class the user class also gets created, so when I do the join and I want to pull everything in at one time, I get a classcastexception. This is how I am calling my query. val retrieved_obj = em.createNamedQuery("findAllSkills...

Migrate from JavaDB to PostgreSQL and cant access database any longer

Hi all I have an application on Glassfish v2 ( on Mac OS 10.5.8 and Java 1.6 ) that uses JavaDB and Toplinks that comes with the Glassfish bundle. Everything works fine. I have installed PostgreSQL 8.4 and the JDBC v4 driver. Both Glassfish and Postgres server run on localhost. From Netbeans, I create a connection to a database on the P...

hibernate search + spring3 + jpa

I'm trying to integrate hibernate search in my project. My models are indexed, but for some reason my search queries do not return any results. I've been trying to solve this issue for a few hours now, but nothing I do seems to work. Domain object: @Entity @Table(name = "roles") @Indexed public class Role implements GrantedAuthority { ...

JPA @NamedQuery with two tables, possible??

Hi all, I'm having a kind of dummy problem, I need to make a @NamedQuery with a join with other table, some simple thing. But in all my @NamedQuery I'm only dealing with my mapped Object/Table. For example in my Object/Table Mapped cars: @NamedQuery(name = Cars.GET_AVAILABLE_CARS, query = "select c.id from Cars c where c.status = (s...

Hibernate database specific columnDefinition values

Hello, the problem is as follows: We're using hibernate with annotations as O/R Mapper. Some @Column annotations look like: @Column(columnDefinition = "longblob", name = "binaryData", nullable = true) or @Column(columnDefinition = "mediumtext", name = "remark", nullable = true) with the columnDefinition attributes being mysql speci...

JPA List field without another Model

Hi, I would like to know if there is anyway I can do something similar to the following thing with JPA: @ManyToMany(cascade=CascadeType.PERSIST) List<String> trackKeywords; Or do I need to create another model with a String attribute? ...

JPA setParameter when dealing with "NOT IN (:param)"

Hi all, I'm trying to set a parameter in my query, for example: select * from Cars where Cars.color NOT IN (:color_params) And when I'm adding the parameter in my JavaClass is like: ... query.setParameter("color_params", "RED,BLUE"); ... And this is not working, is only working with only one parameter. I've tried with "'RED','BL...

EntityManager fails to instantiate using JPA/Hibernate when I add a OneToMany annotation

I have been struggling with not being able to have the EntityManager be instantiated when I add a OneToMany column to a class that already has a OneToMany column. Right now the EducationInfo has a OneToOne to user, since each row will be unique to a person, but I want to be able to load all the education information given a username. I...

How to generate JPA mapping file from the JPA annotated entity classes?

I am using openjpa runtime of JPA specification. At development time I am using annotations to configure jpa entities. At Integration, Pre-Production and and Production environment, I am using orm mapping files to configure entities. Please suggest a tool which can generate mapping files from jpa annotations, so that these mapping files ...

Good design for persisting a JPA domain object

I have a domain object that stores some metadata and some raw bytes. This is used for storing binary objects such as PDF documents and images. I would like to persist the metadata in a database so it can be easily queried but I want to store the raw bytes in the file system for performance reasons. What is a good design for achieving th...

eclipse existing maven project add jpa support ?

how to add jpa support for existing maven project i tried project-->configure--> convert to jpa project (there is no this option) but for my other projects, such option available... can comment? I already have existing mven project and i want to generate jpa entity from tables. no need to create new jpa project right? ...

spring multiple @transactional datasource

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="data.emf" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="transactionManager2" class="org.springframework.orm.jpa.JpaTransactionManager"> ...

How to configure transaction management for working with 2 different db in Spring?

I have 2 databases (MySql and HSQLDB). I configured 2 data sources and 2 EntityManagerFactory beans. I can also configure 2 correspondent JpaTransactionManager beans. But I don't know how to specify which of them should be used to manage transactions for concrete service-class. I want to use @Transactional annotation for that purpose, ...

persistence-unit as RESOURCE_LOCAL or JTA?

1.may i know what is the different of both? both also supported by all database right? 2. jpa transactionmanager and jta transactionmanager different? can explain? ...

Spring jta-transaction-manager

Using Spring: can jta-transaction-manager use id as name so that I can pass it as REF to my service layer like below? is tx:jta-transaction-manager can only be used for je22 container? I mean for Tomcat, I need to do it manually, like below: <tx:jta-transaction-manager id="name_transactionmanager"/> &lt;bean id="projectService" clas...

How to define column that is not actually related to another table by keys, but by keywords

I am using JPA to see how helpful it will be, rather than using straight SQL, and I realized today that one of my columns is incorrect. I have a playlist application. Each playlist has a title and a list of keywords that signify the songs to include. So, I may have this as one row, where there are three keywords. Exercise steady...

Mapping Relationships with Hibernate

I'm still learning how to set up these mappings using the JPA annotations so this may be a beginner mistake. I have a User class and a Course class. In the database each Course has a User foreign key in each row (think of the User as the teacher teaching the Course). So each User can have multiple Courses, but each Course has only one U...

EntityManager initialization best practices

When using EntityManager, is it better to get one instance with PersistenceContext and pass it around in my program, or should I use dependency injection more than once? In my application each client will communicate with a stateful session bean, and each bean needs to use EntityManager at some point. I guess that bean methods are invoc...