java - Spring data JPA - Exclude ID column from one entity parameter -


i have 2 entities :

@entity public class car {      @id     private long id;      @onetoone     private engine engine; } 

and other 1 :

@entity public class engine {      @id     private long id;      @column     private string value1;      @column     private string value2; } 

in jparepositoy interface, :

public interface carrepository extends jparepository<car, long> {      public car findbyengine(engine engine); } 

but method doesn't return entity stored, because created engine doing :

engine engine = new engine("somevalue", "somevalue"); 

without setting engine's id stored in database.

so know if possible exclude column id ? if no, way :

@query("select c car c c.engine.value1 = :value1 , c.engine.value2 = :value2") findbyengine(@param("value1") string value1, @param("value2") string value2) 

?

related question : if have onetomany relationship instead of onetoone, like

@entity public class car {      @id     private long id;      @onetomany     private list<engine> engines; } 

how can request have (still without id column) :

public car findbyengines(list<engine> engines); 

thanks lot !

this @query("select c car c c.value1 = :value1 , c.value2 = :value2") not correct jpql query scenario, not have value1 , value2 in car entity.

correct 1 be:

@query("select c car c c.engine.value1 = :value1 , c.engine.value2 = :value2"). 

you can try method name, think work:

findbyenginevalue1andenginevalue2(string value1, string value2) 

but list one, not think can make method name.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -