Posts

Showing posts from March, 2016

Hibernate - javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter

Problem:
javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter

Solution:Check that the criteria is being done properly via join (Hibernate "Alias").


Spring batc, H2 - DataAccessResourceFailureException Could not obtain last_insert_id() Invalid parameter count for "LAST_INSERT_ID", expected count: "0"; SQL statement

Problem: Environment:
Spring BatchTest database: H2 org.springframework.dao.DataAccessResourceFailureException:
Could not obtain last_insert_id();

nested exception is org.h2.jdbc.JdbcSQLException:
Invalid parameter count for "LAST_INSERT_ID", expected count:
"0"; SQL statement:

update BATCH_JOB_SEQ set ID = last_insert_id(ID + 1)

<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="transactionManager" ref="transactionManager" />
        <property name="databaseType" value="mysql" />
</bean>
Solution: <bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <prop…

Java - JSTL, números aleatorios entre valores

Solución: Añadirla etiqueta a la páginaJSP:

<jsp:useBean id="random" class="java.util.Random" scope="application"/>

, y la siguiente etiquetapara generarun número aleatorio:


${random.nextInt(N)}


, por ejemplo:
Generar un número aleatorioentre 1 y4,con el fin demostrarun fondo diferenteen cadaactualización de la página:

<img src="../img/background_${random.nextInt(3)+1}.jpg">

Java - getResourceAsStream returning null

Problem: ProcessTest.class.getResourceAsStream("H2/ddl/spring_batch/schema-drop.sql");
Solution: Check that the folder (""H2/ddl/spring_batch") is part of the project classpath

in eclipse:
Right click on projectClick "Build Path"Click "Configure Build Path..."Select "Java Build Path"Edit "Source" accordingly

Java, Mongo - Start mongo connecting to replica set

Mongo - Start mongo connecting to replica set

$ mongo --host <replica_set_name>/<hostname_1>:<host_port_1>,host2[:porthost1],host3[:porthost3] <database_name>
<replica_set_name>: Probably defaults to "rs0"Find the pairs <host>:<port> using the mongo command rs.status()

Mongo - error "not master and slaveOk=false"

Problem: listDatabases failed:{ "ok" : 0, "errmsg" : "not master and slaveOk=false", "code" : 13435 } at src/mongo/shell/mongo.js:47
Solution: Make sure you have the replication set: rs.initiate();

Java, Mongo - BasicBSONList can only work with numeric keys not:

Problem
BasicBSONList can only work with numeric keys, not: [url]
Solution:Looking at the Intelij debug output the solution became obvious:

offers = {BasicDBList@5718}  size = 1
  0 = {BasicDBObject@7368}  size = 12
     0 = {LinkedHashMap$Entry@7371} "@type" -> "Offer"
     1 = {LinkedHashMap$Entry@7372} "availability" ->
     2 = {LinkedHashMap$Entry@7373} "name" -> "xxx"
     3 = {LinkedHashMap$Entry@7374} "description" -> "yyy"
     4 = {LinkedHashMap$Entry@7375} "itemCondition" ->
     5 = {LinkedHashMap$Entry@7376} "price" -> "378.56"
     6 = {LinkedHashMap$Entry@7377} "priceCurrency" -> "EUR"
     7 = {LinkedHashMap$Entry@7378} "priceSpecification" -> " size = 1"
     8 = {LinkedHashMap$Entry@7379} "offerID" -> "2"
     9 = {LinkedHashMap$Entry@7380} "seller" -> " size = 2&q…

Play, EBean - SQLException Column Index out range 0 < 1

Problem: Caused by: java.sql.SQLException: Column Index out of range, 0 < 1.
Solution: Ebean "translates" the result columns names to "productEanId", "productId" and "ean". The solution is to give as alias the exact same names of the property to which the columns are going to be assigned: