I ran into what I thought as an issue while I was using the sequence ID generation strategy in JPA. The JPA provider I am using is Hibernate. I think sharing my experience will save someone some time.
To use a sequence (For e.g. Oracle sequence) to generate values and assign them to the ID field of your persistence object, you will following something like this:
@Column(name = "ITEM_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="ItemIdSeqGenerator")
@SequenceGenerator(name="ItemIdSeqGenerator", sequenceName="ITEM_ID_SEQ", allocationSize=1)
private long itemId;This means the following things: The @Id annotation says that the field itemId is a primary key.The @Column annotation says that the corresponding column in the database is ITEM_ID.The @GeneratedValue says that the value that needs to be populated in the itemId should be generated, while that object is persisted. The strategy to generate the value is to make use of a…
Recently one of the applications that I developed started throwing exceptions, that had the following message: SQL state ; error code ; ORA-03111: break received on communication channelWhen I googled around, I couldn't come across anything useful. Sadly enough most of the sites just showed the documentation for that error, without any explanation from anyone experiencing that issues. So here you go, with the best possible explanation that I could come up with.
My application sets two things on the connection that is throwing this exception: It sets the fetchSize to be 2500 rowsIt sets the query timeout to be 10 secondsThe database server and the application are separated over a long latency network (actually there is a NetEm box that emulates the long latency between these two boxes) which has a latency characteristic of 50+/-5 milliseconds. This is the whole setup.
It is important to understand how the timeout is handled by the Oracle client (in my case JDBC client). On…
Question: What is the most efficient way of creating a collection (Set, List or Map) with a single element?
Answer: The most efficient way of creating a collection with a single element would be to make use of the Collections.singletonXXX() methods. Collections.singleton - To create a set that has only one element.Collections.singletonList - To create a list that has only one element.Collections.singletonMap - To crate a map that has only one entry.The collections returned from these methods are immutable.
Compare these methods with Collections.unmodifiableXXX() methods. The umodifiableXXX methods already accept a collection as an argument.