Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Problems using the @ClassExtractor annotation
Problems using the @ClassExtractor annotation [message #953265] Mon, 22 October 2012 01:28 Go to previous message
Cyrill Zadra is currently offline Cyrill Zadra
Messages: 3
Registered: October 2012
Junior Member
Hi there

I'm having problems using the classextractor annotation.. so I tried to reproduce the problem in a simple example.
In this example there are 2 entities. The entity Car and the entity vw which extends car. The classextractor class does always return a Car.class.


@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@SequenceGenerator(name = "CarIdGenerator")
@ClassExtractor(TypeExtractor.class)
public class Car implements Serializable {

	@Id
	@GeneratedValue(generator = "CarIdGenerator")
	private long carId;

	private String name;
	private String descr;
	private static final long serialVersionUID = 1L;

	public Car() {
		super();
	}   
...
}




@Entity
public class VW extends Car implements Serializable {
	
	private String color;
	private static final long serialVersionUID = 1L;

	public VW() {
		super();
	}   
...  
}



public class TypeExtractor extends ClassExtractor {
	
	@Override
	public Class extractClassFromRow(Record databaseRow, Session session) {
		
		return Car.class;


	}

}


Here's the code snippet where I create the car instance an persist it to the database.

   em.getTransaction().begin();
   Car car = new Car();
   car.setName("Super Car");
   car.setDescr("Fast and Super");
   em.persist(car);
   em.getTransaction().commit();



[EL Finer]: 2012-10-21 21:04:08.987--ClientSession(1547555875)--Connection(39892115)--Thread(Thread[main,5,main])--begin transaction
[EL Fine]: 2012-10-21 21:04:08.987--ClientSession(1547555875)--Connection(39892115)--Thread(Thread[main,5,main])--INSERT INTO CAR (CARID, DESCR, NAME) VALUES (?, ?, ?)
	bind => [1, Fast and Super, Super Car]
[EL Finer]: 2012-10-21 21:04:08.996--ClientSession(1547555875)--Connection(39892115)--Thread(Thread[main,5,main])--commit transaction
[



.. but refreshing the newly created instance returns always an EntityNotFoundException

   em.refresh(car);


Exception in thread "main" javax.persistence.EntityNotFoundException: Entity no longer exists in the database: ch.tie.poc.jpa.Car@2b177c9.
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.refresh(EntityManagerImpl.java:963)
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.refresh(EntityManagerImpl.java:849)
	at ch.tie.poc.jpa.Main.main(Main.java:33)



[EL Finest]: 2012-10-21 22:19:49.994--UnitOfWork(1189942303)--Thread(Thread[main,5,main])--Execute query ReadObjectQuery(referenceClass=Car )
[EL Finest]: 2012-10-21 22:19:49.995--ServerSession(1313157506)--Connection(1456488724)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2012-10-21 22:19:49.995--ServerSession(1313157506)--Connection(1456488724)--Thread(Thread[main,5,main])--SELECT t0.CARID, t0.DESCR, t0.NAME, t1.CARID, t1.COLOR FROM CAR t0, VW t1 WHERE ((t0.CARID = ?) AND (t1.CARID = t0.CARID))
	bind => [1]
[EL Finest]: 2012-10-21 22:19:49.998--ServerSession(1313157506)--Connection(1456488724)--Thread(Thread[main,5,main])--Connection released to connection pool [default].



And looking at the log you can see its joining the two tables car an vw. What am I doing wrong? Shouldn't it only select the car table? Hope someone can give me a hint.

Could reproduce this with eclipselink 2.3.3 and 2.4.0.

thanks and regards
cyrill
 
Read Message
Read Message
Read Message
Previous Topic:using eclipselink in Eclipse' Tomcat
Next Topic:JPA mapping problem. Multiple values
Goto Forum:
  


Current Time: Tue May 21 05:33:21 EDT 2013

Powered by FUDForum. Page generated in 0.02154 seconds