String primary keys
by Norman Bauer
Hello all,
I am working with a legacy database where pretty much all the primary
keys are strings and user defined. I'm using Grails to build out the
front end to the underlying database (Rocket UniVerse and my own
customized dialect for U2). Using GORM I can map columns and rows
fairly easily and view all the data, the problem starts when I want to
add a new record, I get the message below:
Executing action [save] of controller
[onemoretest.CustomerInfoController] caused exception: this id
generator generates long, integer, short; nested exception is
org.hibernate.id.IdentifierGenerationException: this id generator
generates long, integer, short
Which of course is because I am using user defined string via "id
generator:'assigned', column: "@ID", type:'string'" in my domain.
My question is this, where can I override that behavior. It would be
great to do it in my dialect so as not to break other unknown things
elsewhere.
Thanks,
Norm
14 years, 2 months
Context-based Logging
by John Verhaeg
I'm currently going through the codebase trying to convert our use of slf4j for logging to jboss-logging. In doing so, I've noticed that all of the current loggers are named using the package-qualified name of the enclosing class that define them. JBoss-logging offers a similar concept in that loggers are associated with category names, but with the difference that multiple loggers can be associated with the same category.
I'm still fairly new to working with the Hibernate codebase, but based on other projects I've worked on, I was thinking that maybe we should *additionally* introduce some type of context-based logging moving forward, where we'd supply logging contexts that represent the processes in play, as opposed to the structural organization of loggers that names / categories typically represent. To fully realize the power of these contexts, you'd want to support the idea of sub-contexts that could be active within other contexts (capturing when sub-processes are executed within higher-level processes).
Just to clarify via an example, consider the code involved with making a query using hql. From what I can see in the existing code, one of the sub-processes involved with such a query involves copying the result set so that a pristine copy can be maintained and cached by the session, such that it won't be impacted by local changes to those results by the user between commits. So let's assume there's some issue a developer encounters while creating a query, and the underlying problem has something to do with copy sub-process. Using contexts, the developer would be able to configure his underlying logging framework to enable, say, the "query" context and set the logging level to debug or trace. Ideally, he'd get enough information from these logs to determine that things begin to go awry after the results are copied. This, of course, presumes a message is logged in the "query" context indicating when the "copy results" sub-process is triggered, possibly even specifying in that message the sub-context associated with that sub-process. Now the developer knows to enable this new context and run through the scenario again to isolate the problem. He doesn't have to care or know which or how many classes are involved in either the outer hql process or the subprocess responsible for copying results.
So one intended benefit of using contexts would be to make it easier for developers, and possibly even developers' end-users, to determine which log messages to enable/filter related to some problem their trying to hunt down, while minimizing their need to understand the structure of code internal to the Hibernate libraries. This approach should also help decouple the logging and coding concerns such that, for instance, if a method is moved to a different class, there is no impact on how messages are logged (assuming the same contexts are still applicable).
While we certainly could specify category names that more represent processes or logical structure rather than simple package and class names (physical structure), I'd still be concerned about code that happens to be reused within multiple processes or services. Assuming it's important for a significant amount of this type of "utility" code to log messages (this might be a big assumption), which category of logger would you choose? You could pass in the logger, but that would require changes to any existing APIs. You could also just provide a separate category for this type of code, but then you'd blurring what it means for a category to represent a "process".
So I'm thinking that using the jboss-logging NDC facility might be a good way to support process-based contexts. This facility allows us to push and pop contexts on and off a global stack (maintained by the jboss-logging framework) at the boundaries of these processes. Of course, we'd have to document the contexts that we use and the processes that they're tied to. The disadvantage here would be the discipline we'd have to exercise to do this properly. Pushing and popping contexts would need to be treated similarly to beginning and ending a transaction, where contexts that are popped off of the NDC stack would reside within finally blocks. One other thing to consider is we'd probably want to provide some documentation about how to support NDC using simple JDK logging, since this isn't supported out-of-the-box.
So is any of this worth the effort? Are my concerns valid? Is using category names to represent logical structure enough? Thoughts?
JPAV
14 years, 2 months
On possible extensions for the validator
by Federico Mancini
Hi all,
I am new to the list and I am opening this thread on Emmanuel Bernard's
suggestion, in order to
discuss some possible extensions to the validator (jsr 303) I have been
working on with a couple of collegues.
Mainly it concerns the possibility to extend composition with boolean
operators (ex.: A field is either in the range 1-10 OR 20-30 AND
notNull) and allow validation of sets of interdependent properties
(ex.: EITHER the name field is notNull OR the surname field is notNull/
AT LEAST 1 field must be filled/etc....).
A description of the experimental framework we implemented can be found
here http://www.ii.uib.no/publikasjoner/texrap/pdf/2009-389.pdf , and
some further discussion on the choices we made here
http://www.ii.uib.no/~federico/papers/Annotations.pdf.
I hope this might be of some interest for the Hybernate Validator project,
but, even if not, it would be nice to get some feedback.
Thanks,
Federico Mancini
14 years, 2 months
<meta/> and HBMBinder
by Steve Ebersole
HBMBinder.bindRoot excepts a java.util.Map parameters called 'inheritedMetas'.
Thing is, that parameter is really useless. That method is called from a
single place in the Hibernate Core code and that value is defined as
CollectionHelper.EMPTY_MAP in said caller.
So either this code changed in such a way that this parameter was no longer
needed but never removed, or another project uses it differently. Do we need
this passed in still?
---
Steve Ebersole <steve(a)hibernate.org>
http://hibernate.org
14 years, 2 months
null values in validation
by Federico Mancini
Hi,
we managed to implement a first version of boolean composition for the
validator, and it seems to require very few changes to the code.
We also opened an issue on Jira about that.
From the tests we ran, the constraints seem to be evaluated correctly,
but we have some strange behaviour regarding the reporting of
violations, which we are investigating.
Reporting violations would also be an interesting subject of discussion
in itself, since we cannot say anymore that a composed constraint fails
if just one of the constraint
composing it fails. We have to evaluate all the tree of constraints
before knowing the final outcome (if it is a disjunction for example).
In this case we thought it might be best to report everything as a
single violation by default.
Another thing we wondered about is the default behaviour of built-in
constraints when they validate null values. Are they supposed to succeed
on null values by default?
In other words, do we assume that unless the user specifies @NotNull, it
means that a null value is valid and should not generate an exception
for other constraints?
Federico
14 years, 2 months
Re: [hibernate-dev] Fwd: [Hibernate-JIRA] Closed: (HHH-5616) Switch to Gradle for builds
by Steve Ebersole
Strange. Quite a few of us have been able to do this successfully.
Maybe you ran that as root? That would explain why user home there is Users
root (extrapolating Linux knowledge to Mac).
In mine I just noticed that while it works, the paths to the jar are relative
from the IntelliJ variable $MODULE_DIR. If you look at the .iml file, is
yours the same? Not sure why they do it that way as opposed to an absolute
path. Still does not explain why yours is off, but I can look into that.
On Friday, October 15, 2010, at 05:42 am, Galder Zamarreño wrote:
> Where are you supposed to execute 'gradle idea' from? If I execute it from
> the root, the IML files created are pointing to the wrong dependencies,
> i.e.:
>
> •
> /Users/.gradle/cache/org.infinispan/infinispan-core/jars/infinispan-core-4
> .2.0.ALPHA1.jar
>
> Clearly, this should be pointing to:
>
> •
> /Users/z/.gradle/cache/org.infinispan/infinispan-core/jars/infinispan-core
> -4.2.0.ALPHA1.jar
>
> Any idea what is wrong? I can't compile anything from IDEA
>
> On Oct 14, 2010, at 8:07 PM, Steve Ebersole wrote:
> > FYI, I wrapped this up into a blog entry:
> > http://in.relation.to/Bloggers/HibernateGradlePointers
> >
> > On Monday, October 11, 2010, at 08:58 pm, Steve Ebersole wrote:
> >> I should have pointed out some of the basic commands you'll commonly
> >> need. All these can be found in the Gradle User Guide:
> >> http://www.gradle.org/0.9-rc-1/docs/userguide/userguide_single.html
> >>
> >> Most of the stuff we are interested in comes from the Java plugin:
> >> http://www.gradle.org/0.9-
> >> rc-1/docs/userguide/userguide_single.html#java_plugin
> >>
> >> Here is a list of the ones you will currently be using (from any project
> >> in gradle you can get a list of available tasks by executing `gradle
> >> -t`):
> >>
> >> 1) build - Assembles (jars) and tests this project.
> >> 2) buildDependents - Assembles and tests this project and all projects
> >> that depend on it. So think of running this in
> >> hibernnate-entitymanager.. Gradle would assemble and test
> >> hibernate-entitymanager as well as hibernate-envers (because envers
> >> depends on entitymanager).
> >> 3) classes - compiles the main classes
> >> 4) clean - Deletes the build directory.
> >> 5) jar - Generates a jar archive with all the compiled classes.
> >> 6) testClasses - Assembles the test classes.
> >> 7) test - Runs the unit tests
> >> 8) uploadArchives - think Maven deploy
> >>
> >> Especially those of you developing Search, Validator, etc should know
> >> about an additional task:
> >> 9) install - installs the project jar to your local maven cache (aka
> >> ~/,m2/repository)
> >>
> >> In the root project you can perform any task and Gradle will attempt to
> >> perform it on each subproject.
> >>
> >> That should be enough to get you going.
> >>
> >> Oh and you can also execute multiple tasks:
> >> `gradle clean build` runs both the clean and build tasks
> >>
> >> On Monday, October 11, 2010 05:45:29 pm Steve Ebersole wrote:
> >>> I have switched HEAD of hibernate-core to use Gradle for builds. I
> >>> still need to finish up some tasks, but they mostly deal with the
> >>> release process for which I created a follow-up issue.
> >>>
> >>> You can either install Gradle and use the gradle command, or you can
> >>> use "gradle wrapper" by using the ./gradlew (or ./gradlew.bat files
> >>> for our Windows friends).
> >>>
> >>> ---------- Forwarded Message ----------
> >>>
> >>> Subject: [Hibernate-JIRA] Closed: (HHH-5616) Switch to Gradle for
> >>> builds Date: Monday, October 11, 2010, 04:46:57 pm
> >>> From: "Steve Ebersole (JIRA)" <noreply(a)atlassian.com>
> >>> To: steve(a)hibernate.org
> >>>
> >>> [
> >>>
> >>> http://opensource.atlassian.com/projects/hibernate/browse/HHH-5616?page
> >>> =c om .atlassian.jira.plugin.system.issuetabpanels:all- tabpanel ]
> >>>
> >>> Steve Ebersole closed HHH-5616.
> >>> -------------------------------
> >>>
> >>> Resolution: Fixed
> >>>>
> >>>> Switch to Gradle for builds
> >>>> ---------------------------
> >>>>
> >>>> Key: HHH-5616
> >>>
> >>>> URL:
> >>> http://opensource.atlassian.com/projects/hibernate/browse/HHH-5616
> >>>
> >>>> Project: Hibernate Core
> >>>>
> >>>> Issue Type: Task
> >>>> Components: core
> >>>>
> >>>> Reporter: Steve Ebersole
> >>>> Assignee: Steve Ebersole
> >>>>
> >>>> Fix For: 4.0.0.Alpha1
> >>>>
> >>>> Time Spent: 23h
> >>>>
> >>>> Remaining Estimate: 0h
> >>>>
> >>>> http://gradle.org
> >
> > ---
> > Steve Ebersole <steve(a)hibernate.org>
> > http://hibernate.org
> > _______________________________________________
> > hibernate-dev mailing list
> > hibernate-dev(a)lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/hibernate-dev
>
> --
> Galder Zamarreño
> Sr. Software Engineer
> Infinispan, JBoss Cache
---
Steve Ebersole <steve(a)hibernate.org>
http://hibernate.org
14 years, 2 months
problem in implementing the hibernate search
by nitin warkar
Hi all,
I am struggling with the hibernate search, I had been implemented a small
POC on the hibernate search.It works perfectly for my one database table
named as "Item" but when I am trying to use the same configuration for some
other tables then Session.createFullTextQuery(luceneQuery, Item.class);
returns me null result.
I have configure the beans and hibernate configure same as I had used it for
the Item table.
Please help me ASAP trying from last two days.
See the code below....
======================searcher.java file code===============================
*Code:*
String[] productFields = { "name_astp", "description_astp" }; // targeted
fields
// Map<String, Float> boostPerField = new HashMap<String, Float>(2); //
boost
// factors
// boostPerField.put("name_astp", (float) 4);
// boostPerField.put("description_astp", (float) 1);
// QueryParser parser = new MultiFieldQueryParser(productFields,new
// StandardAnalyzer(),boostPerField);
//QueryParser parser = new QueryParser("name_astp", new
StandardAnalyzer());
QueryParser parser = new MultiFieldQueryParser(productFields,
new StandardAnalyzer());
org.apache.lucene.search.Query luceneQuery;
try {
luceneQuery = parser.parse(seachKeyStr);
} catch (ParseException e) {
throw new RuntimeException("Unable to parse query: " + seachKeyStr,
e);
}
Session session =
HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
FullTextSession ftSession =
org.hibernate.search.Search.createFullTextSession(session);
// ftSession=org.hibernate.search.Search.getFullTextSession(session);
Query query = ftSession.createFullTextQuery(luceneQuery); // return,
Item.class
@SuppressWarnings("unchecked")
List<Item> results = null;
try {
results = query.list();
} catch (Exception ex) {
ex.printStackTrace();
}
//======================Item.hbm.xml============================================
*Code:*
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Example 2.7 -->
<hibernate-mapping package="com.manning.hsia.dvdstore.model">
<class name="AmAssetType" table="am_asset_type_astp"> <!-- mapping
externalized in hbm.xml files -->
<id name="id">
<generator class="native"/>
</id>
<property name="name_astp"/>
<property name="description_ast"/>
</class>
</hibernate-mapping>
//============================= hibernate.cfg.xml
=====================================
*Code:*
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate
Configuration DTD 3.0//EN"
"
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Example 2.3 -->
<hibernate-configuration>
<session-factory>
<!-- database configuration -->
<property
name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://
192.168.1.12:3306/dvdstore</property>
<property name="connection.username">root</property>
<property name="connection.password">admin</property>
<property name="hibernate.connection.pool_size">1</property>
<property
name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property
name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
<property name="show_sql">true</property>
<!-- generate schema -->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Hibernate Search configuration -->
<property
name="hibernate.search.default.indexBase">./build/indexes</property>
<property
name="hibernate.search.default.directory_provider">org.hibernate.search.store.RAMDirectoryProvider</property>
<!-- classes mapping -->
<mapping class="com.manning.hsia.dvdstore.model.Item"/>
</session-factory>
</hibernate-configuration>
hope you will get clear idea about what exactly I am trying to do........
Thank you in advance.
--
-Regards
Nitin warkar
3B Productivity Paradigms.
14 years, 2 months