SqlResultSetMapping columns as and entities

后端 未结 1 1576
名媛妹妹
名媛妹妹 2021-01-05 03:50

I am really confused, how does column resultset mapping work? What am I mapping when I use columns instead of entities? Look at this example...

Query q = e         


        
相关标签:
1条回答
  • 2021-01-05 03:58

    You map 4 fields from result set to 2 Java classes: first class is Order entity, and the second is (probably) String that shall contain "item_name" db field.

    DB:                         Java
    ---                         ----
    order_id              --->  \
    order_quantity        --->  Order entity
    order_item            --->  /
    item_name             --->  String
    

    In order to read the query results:

    for (Object[] record : query.getResultList()) {
       Order order = (Order)record[0];
       String itemName = (String)record[1];
    }
    
    0 讨论(0)
提交回复
热议问题