java - Spring MVC: findById - do not include all ManyToOne collections -


I have 3 institutions class A, Class B and Class C. Classes have several teoons with Class B and Class C

If I use / classA / 1 or / classA / abc / 1 from the web browser with a large JSON and classbie class and all Items have been found.

But I want the ID of Classware and Classbis and the ID of the classics.

Where do I have an error?

The simple code is:

  / * --------------------------- --------------- ------------ * / @Entity @Table (name = "CLASS_A") @ Nominee (name = "classaffined", query = "Select C to Class Ace") Public Class Class A Tool Serializable {Private Static Last Long Serial VironUID = 1 L; @Id @ Generated Values ​​(strategy = generation type.INNTITI) @column (exclusive = true, tapable = false) Private INAD; @ManyToOne @JoinColumn (name = "class_b_id", drain = false) Private class B class B; @ManyToOne @JoinColumn (name = "class_c_id", drain = false) Private class class C; @ Private private string description; Public Class () {} // Gates and Setters ...} / * --------------------------------- --------------------- / * @Entity @Table (name = "CLASS_B") @ Named (name = "ClassB.findAll", query = "SELECT c Public Class Classbie Tool Serializable {Private Static Finals Long Serial Yearsian UID = 1l; @ id @ Columns (Exclusive = True, Faucet = Wrong) Private INAD; @ Private Private String Description; @OneToMany (Mapped = "Class B") Private list & lt; Classa & gt; classesA; Public class B () {} // Gates and S Letters ...} / * --------------------------------- ---------- ----------- * / unit @Table (name = "CLASS_C") applies the public class classical SerialJobile {Private constant last long serial VERSIONUID = 1L; @ id @ column (exclusive = true, tap) Qualified = Incorrect) Private INAD; @ Private Private String Description; @OneToMany (mapped = "Classical") Private list & lt; Classa & gt; classesA; Public class () {} // Gates and Setters ...} / * --------------------------------- --------------- ------ * / @Repository Public Class Dao Class A {@Autowired Private SessionFactory session; Public Class Search ID (Id) {Return (Class) This Op. Get Factie.TrustSation () (Class A Class, ID); } Public class efib iii (int id) {return (class) this session. Factory.ceatcent session () .createQuery ("Class A N Left join Fitch N. Class B Left join afich N. classacy an NID = ID:") .setInteger ("id", id) .uniqueResult () ; }} / * ---------------------------------------------- -------- * / @ Controller @ Request Mapping ("/ Category A") Public Sector RestController {@Autowired Private ClassAmanager Manager; @RequestMapping (value = "/ {ID}", Method = RequestMethod.GET, Production = MediaTip.APPLICATION_JSON_VALUE) Public @ResponseBody Class 1 get1 (@Path Variable ("ID") ID) {Return Manager.Findbid ); } @RequestMapping (value = "/ ABC / {ID}", method = RequestMethod.GET, produces = mediaTip.ipilICnggnsnOR.org) public @ResponseBody class get2 (@pass variable ("id") id id) {return manager. FIDBI IDBI); }} / * ---------------------------------------------- -------- * /    

Its a solution that is quite < / P>

Code> ClassC instead of just the events of itself inc.

If you want some code example examples, and I will update the answer

Updated with example:

  Public Sector Fu {Private IIT; Private times; // gates and the setters} public class times {private id id; Private string otherProperty1; Private string otherProperty2; // Gates / Sets} Public Class FooDto {Private Ent ID; Private int bar id; // gates and setters} public class FooMapper {public static FooDto mapToDto (Foo foo) {FooDto DTO = new FooDto (); Dto.setId (foo.getId ()); Dto.setBarId (foo.getBar () getId ().); Return DTO; }} // Returns FooMapper.mapToDto (foo) using Mapper in your Controller Method;   

In doing so, you change your model object into a transfer object, which contains only the attributes you want to see in the serialized JSON.

You do not have to apply this way in this way, for example, if you do not want to create a mapping class, you can move the mapping logic instead of the creator of the DTO object.

I hope this example gives you a general idea

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -