Robben
Robben

Reputation: 463

Hibernate query producing weird symbols in results

I am using java with hibernate.

I just set up my project to use hibernate but I am getting weird symbols/semantics when I execute my query.

I get the following weird symbols/semantics and I am not sure why?

querying all the managed entities... executing: from CarProduct WHERE carid='27883836' Hibernate: select carproduct0_.car_id as car1_0_, carproduct0_.attribute as attribut2_0_, carproduct0_.product_id as product3_0_, carproduct0_.value as value4_0_ from car_product carproduct0_ where carproduct0_.car_id='278838836'


Here is my main class:

import java.util.Map;

public class Main {
    private static final SessionFactory ourSessionFactory;
    private static final ServiceRegistry serviceRegistry;

    static {
        try {
            Configuration configuration = new Configuration();
            configuration.configure();

            serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
            ourSessionFactory = configuration.buildSessionFactory(serviceRegistry);
        } catch (Throwable ex) {
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static Session getSession() throws HibernateException {
        return ourSessionFactory.openSession();
    }

    public static void main(final String[] args) throws Exception {
        final Session session = getSession();
        try {
            System.out.println("querying all the managed entities...");
            final Map metadataMap = session.getSessionFactory().getAllClassMetadata();
            for (Object key : metadataMap.keySet()) {
                final ClassMetadata classMetadata = (ClassMetadata) metadataMap.get(key);
                final String entityName = classMetadata.getEntityName();
                final Query query = session.createQuery("from " + entityName + " WHERE carid='278838836'");
                System.out.println("executing: " + query.getQueryString());
                for (Object o : query.list()) {
                    System.out.println("  " + o);
                }
            }
        } finally {
            session.close();
        }
    }
}

Upvotes: 0

Views: 175

Answers (1)

Mikko Maunu
Mikko Maunu

Reputation: 42114

What you see is perfectly normal SQL query where SQL aliases are used.

For example because of

from car_product carproduct0_

we can on other part of query use this alias as follows:

select carproduct0_.car

Those aliases are of course not very human friendly named.

Upvotes: 1

Related Questions