Reputation: 4681
I have a pojo that I want to insert into a database (Sql Server). When I run my code, I'm getting a "the conversion from UNKNOWN to UNKNOWN is unsupported". My question is, if my pojo and my database have everything named the same, can I just write it directly like this (or are there maybe annotations that'd let me do that)? Or do I always need a bean in here to do the mapping? I'm thinking this error might be because I'm jamming a pojo in where it doesn't belong.
In my main class I have
@Inject
TradePersistenceService dataService;
Trade trade = new Trade();
trade.setSec_id(-1);
trade.setSourceload_id(-1);
trade.setCusip("123");
dataService.insertTradeMessage(trade);
And in my spring configuration I have
<integration:channel id="InsertTradeMessageRequestChannel" />
<integration:channel id="InsertTradeMessageReplyChannel" />
<integration:gateway id="RTService"
service-interface="com.whatever.TradePersistenceService">
<integration:method name="insertTradeMessage"
request-channel="InsertTradeMessageRequestChannel" reply-channel="InsertTradeMessageReplyChannel" />
</integration:gateway>
<int-jdbc:outbound-gateway request-channel="InsertTradeMessageRequestChannel"
query="insert into MSRB_RTRS (Sec_ID, SourceLoad_ID, CUSIP) values (:Sec_ID, :SourceLoad_ID, :CUSIP"
data-source="rmsa">
</int-jdbc:outbound-gateway>
In the database, I have a table called MSRB_RTRS with two numeric columns, and a varchar.
Finally, my pojo (with the standard getters and setters omitted here to reduce clutter)
public class Trade {
int sec_id;
int sourceload_id;
String cusip;
}
Upvotes: 0
Views: 1001
Reputation: 121212
First of all you have to use update
, not query
, for INSERT
.
Second it isn't clear how that Sec_ID
is related to the sec_id
property in the Trade
class.
You should consider to use something like:
<beans:bean id="parameterSourceFactory" class="org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory">
<beans:property name="parameterExpressions">
<beans:map>
<beans:entry key="Sec_ID" value="payload.sec_id" />
<beans:entry key="SourceLoad_ID" value="payload.sourceload_id" />
</beans:map>
</beans:property>
</beans:bean>
You can find more info in the Reference Manual:
In the example above, messages arriving on the channel labelled input have a payload of a map with key foo, so the [] operator dereferences that value from the map. The headers are also accessed as a map.
Upvotes: 1