Idąc w opałach tutaj, czy za iBatis? Jest to prawdziwa program do mapowania zapytań typu "down to earth" (w pewnym momencie waham się nazwać go strukturą ORM). Trzeba tworzyć pliki XML jak ten:
<mapper namespace="org.mybatis.jpetstore.persistence.ProductMapper">
<cache />
<select id="getProduct" parameterType="string" resultType="Product">
SELECT
PRODUCTID,
NAME,
DESCN as description,
CATEGORY as categoryId
FROM PRODUCT
WHERE PRODUCTID = #{productId}
</select>
</mapper>
który drutów element odwzorowujący jak ten:
public interface ProductMapper {
Product getProduct(String productId);
}
, który pozwala na dostęp do danych z usług tak:
@Autowired
private ProductMapper productMapper;
public Product getProduct(String productId) {
return productMapper.getProduct(productId);
}
Które można podłączyć do źródła:
<!-- enable autowire -->
<context:annotation-config />
<!-- enable transaction demarcation with annotations -->
<tx:annotation-driven />
<!-- define the SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="org.mybatis.jpetstore.domain" />
</bean>
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="org.mybatis.jpetstore.persistence" />
</bean>
Zobacz także the full petstore example.
Nie jestem jednoznacznym fanem iBatis, ale może on pasować do twoich potrzeb w tym konkretnym przypadku.
Jeśli już wiesz, że są podobne pytania, to wspaniale, że mówisz nam o nich. Ale mówienie nam ** dlaczego ** te pytania nie są tym, czego chcesz, byłyby jeszcze lepsze! –
Jaki jest twój problem przy pisaniu go samemu? –
jaki jest problem z hibernacją, jego wielki ... – NimChimpsky