Question

Assuming Tomcat 7, Servlets 3, MySQL 5.5, etc...

In my app I am storing database IDs as INT in the database. In my DAOs I am mapping them to Long in the Enities.

As I write controllers etc I find myself doing a lot of work testing nulls and parsing values from strings. i.e. the forms pass parameters as Strings that need to be parsed. And if you parse a null or blank you get an exception. It's a lot of work to check all this stuff.

Since it's much easier to pass Strings back and forth, would it be architecturally acceptable to just leave the IDs as Strings in the Entities? SQL can do the conversion for me ps.setObject("123". It seem I could save a lot of effort. It's not like I'm operating on the IDs - except in SQL...

Or, what am I not thinking of?

I'm trying to simplify this... Dealing with an exception and cleaning up is no less work.

Project project = new Project();
String param = req.getParameter("id");
if(param!=null && param.length()>0){
    Long projid = Long.parseLong(param);
    project = projectDao.getProjectById(projid);
}

No correct solution

OTHER TIPS

no matter if it's string or long, it will always be a problem when it's null, because primary key can't be null, right? plus, a string as primary key is not efficient from database point of view, because it's much worse to compare them and search on strings, even with indexes applied

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top