7.08.2011

Resolving Postgres "returning auto generated keys no supported"

I discovered Jean-Pol Landrain's, "TriggerAssignedIdentityGenerator" to address the issue of the Hibernate ID Generator not supporting an Id created by the database via a BEFORE INSERT trigger.

However the TriggerAssignedIdentityGenerator design for Oracle did not work for the older JDBC PostgreSQL driver which doesn't support the return of auto-generated keys.

The probem was resolved by changes to the 'prepare' and 'executeAndExtract' methods:




protected PreparedStatement prepare(String insertSQL, SessionImplementor session) throws SQLException {

return session.getBatcher().prepareStatement(insertSQL + " RETURNING *");
}

protected Serializable executeAndExtract(PreparedStatement insert) throws SQLException {

insert.execute();
// get the new id back
ResultSet rs = insert.getResultSet();
if (rs.next()) {
return new String(rs.getString(1)); // assume that 1 is id
}

throw new SQLException("Returned no id in resultset");

}

postgres create trigger error relation does not exist 42P01

PostgreSQL 8.4: When attempting to create a simple trigger the executes a function, for a table that exists, I was getting a 42P01 error: relation "table_name" does not exist

CREATE TRIGGER genUuid
BEFORE INSERT ON table_name
FOR EACH ROW EXECUTE PROCEDURE generate_function_v1();

This was simple resolved by including the schema name along with the table as follows:

CREATE TRIGGER genUuid
BEFORE INSERT ON my_schma.table_name
FOR EACH ROW EXECUTE PROCEDURE generate_function_v1();

6.21.2011

org.hibernate.HibernateException: Unable to locate current JTA transaction

It started with a "org.hibernate.HibernateException: Could not find datasource" which was resolved by moving the hibernate-cfg.xml to the root folder (above WEB-INF). Once this was resolved my servlet returned a "Unable to locate current JTA transaction" transaction error. The postgres datasource configured via JBoss indicated status DOWN.

Error text:

org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:88)
org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:621)

occurs when getSessionFactory is attempted. Direct connection to db (w/o JBoss DS) works fine.

4.06.2011

.NET MVC DropDownList, SelectList and Selected Value

If you've tried using the Html.DropDownList in .NET MVC you know that it the selectedValue of the populating SelectList doesn't work. The frequently posted workaround, is to change the name of DropDownList to something other that the field it is supposed to be bound to.

Perfect, now the value is selected in the list as expected. BUT, the problem with this however is that is the DropDownList no longer binds to the model as needed. Since we've changed the name, updates to the database do not work. After reading numerous posts on Stackoverflow I discovered zero solutions.

Here is how I resolved it:

Assuming that your SelectList is constructed in your Controller or ViewModel like this:

CatsRepository CatsRepo = new CatsRepository();
CatsList = new SelectList(CatsRepo.FindCats(), "CatId", "Category", Content.CatId);


The HTML.DropDownList can be constructed in your control like this:


%lt;input type="hidden" name="CatId" id="CatId" value="" /%gt;
%lt;%= Html.DropDownList("CatIdList", Model.CatsList, new { @onchange = "CatId.value = this.value"})%%gt;

In Summary,

1) I renamed my "CatId" bound DropDownList to "CatIdList".
2) Then I added a hiddel field named "CatId" setting it's value to "".
3) I added a "new { @onchange = "CatId.value = this.value"}" as an htmlAttribute to my DropDownList, so when a different value is picked it updates the hidden field value accordingly.

1.19.2011

SOAPUI - Failed to import wsdl

It seems that this is a very generic error, but if you examine the SOAPUI logs you can usually find out what's causing it. The SOAPUI error log (found in the "soapUI Logs" in the eclipse soapUI perspective tabs) shows the error details.

In my case, there was a SchemaException: Error loading schema types. My WSDL referenced numerous .xsd schemas, one of which was on a secured remote site. I changed the schema reference to a local address using the 'schemaLocation=../localpath/some.xsd' attribute of the import tag and all worked fine.

How to check if JBoss WS is deployed

It seems like a simple task, but it took me a little while to determine whether or not my Web service deployed to JBossWS from Eclipse actually got deployed. Just browse to http://localhost:8080/jbossws/services, and you can see what services are active on the server.

3.19.2009

Big Fish, Little Fish: Tracking Web Startups

Gone are the days of the dotcom boom, but there are still alot of new ideas being launched. After spending some time on WebWare and KillerStartups you can see the current trends, which as of late are social networking and micro-blogging. There are all kinds of widgets and mash-ups that take advantage of the API's that the bigger fish are providing.

Web Business Models

Making money from an idea. This is something most of us would like to learn more about. Dan Zamboni over at Box UK gives a nice breakdown of Web business models. Dan's Web business model taxonomy is loosely related.

In general, Dan defines 2 top-levels "immediate" and "long-term". The immediate (short-term) level breaks down into what we see in most Web revenue models --subscription based, one-time payments or 3rd-party (sponsor/partner/advertiser) supported. At the long-term level (do you have the patience?) the general idea is to build an audience before expecting any return -- "Attract a substantial audience before monetizing".

Now to figure out which ones are the most successful. What do you think?

3.18.2009

Tripping on Egos

This isn't really a post, more like a stumple upon. Today, I was lucky enough to discover a large ego pool: http://www.monitortalent.com. How nice that these folks are there to guide us.

Why Unstructured Classification Matters?

Clay Shirky once write a great article about the importance of user defined classification. This is even more important for the socially networked "Web 3.0" CMS. Of course a CMS will let the publisher classify content by format/function (ie; content type) and topically (ie; categories,sub category,etc..) -- But the new CMS will also let me "tag" my content and generate another map it.