Can't get EntityManager access in JSP/Servlet

Hi all,
our team has started a EJB project (EJBs + JPA configurations)
we managed to access the configured JPA (EntityManager etc) within the EJB instance; however we don't know how to access the EntityManager within JSP/Servlet
Our project's structure:
1 EJB project (EJB classes, EntityBean classes, JPA configuration + eclipselink)
1 Web project (for JSP, Servlets)
the main problem is ... we can't access EntityManager(s) in JSP / Servlets (and we already tried using Struts2.0 to replace servlets/jsp... the problem is the same... so it is not ... the matter of choosing the view technology...)
Jason

Hi Jason,
How i tried to get EntityManager is as following:
Suppose I want to define my Persistence unit like Following:
*<Your-EAR>/APP-INF/classes/MyEmployee.java*
"*MyEmployee.java*"
package entityA;
import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import javax.persistence.*;
@Entity()
@Table(name="MYEMPLOYEE")
public class MyEmployee implements Serializable {
     //default serial version id, required for serializable classes.
     private static final long serialVersionUID = 1L;
     private Long empno;
     private String empname;
public MyEmployee() {
     @Id()
     @Column(name="EMPNO", unique=true, nullable=false, precision=22)
     public Long getEmpno() {
          return this.empno;
     public void setEmpno(Long empno) {
          this.empno = empno;
     @Basic()
     @Column(name="EMPNAME", length=15)
     public String getEmpname() {
          return this.empname;
     public void setEmpname(String empname) {
          this.empname = empname;
     public boolean equals(Object other) {
          if (this == other) {
               return true;
          if (!(other instanceof MyEmployee)) {
               return false;
          MyEmployee castOther = (MyEmployee)other;
          return new EqualsBuilder()
               .append(this.getEmpno(), castOther.getEmpno())
               .isEquals();
     public int hashCode() {
          return new HashCodeBuilder()
               .append(getEmpno())
               .toHashCode();
     public String toString() {
          return new ToStringBuilder(this)
               .append("empno", getEmpno())
               .toString();
And I have Placed My "*persistence.xml*" file in *"<Your-EAR>/APP-INF/classes/META-INF/persistence.xml"*
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
     version="1.0">     
     <persistence-unit name="JPA_A_EJB" transaction-type="RESOURCE_LOCAL">
          <provider>org.hibernate.ejb.HibernatePersistence</provider>
          <class>entityA.MyEmployee</class>
          <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
               <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
               <property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
               <property name="hibernate.connection.username" value="jack"/>
               <property name="hibernate.connection.password" value="password"/>
          </properties>
     </persistence-unit>     
</persistence>
***********************************HOW I Access The Above Unit from my EJB mentioned Below*******************************
"*EmployeeSessionBean.java*"
package sfsbA;
import entityA.*;
import javax.ejb.*;
import javax.persistence.*;
@Stateless
public class EmployeeSessionBean implements EmployeeSessionRemoteIntf
*@PersistenceContext*
protected EntityManager entityManager;
*///NOTE: Using the Above Technique You can access the "EntityManager" Object in your Servlets As well...Just write the Above two Lines inside your Servlet*
public void createEmployee(Long empno,String empname) throws Exception{
          System.out.println("\n\tcreateEmployee() called. EntityManager entityManager = "+entityManager);
          MyEmployee employee = new MyEmployee();
employee.setEmpno(empno);
employee.setEmpname(empname);
entityManager.persist(employee);
          System.out.println("\n\t Entity Manager has persisted the Employee Information...");
int count = 0;
public EmployeeSessionBean() {
System.out.println("\n\t EmployeeSessionBean--> EmployeeSessionBean() invoked");
@Init("create")
public void initMethod() throws CreateException {
System.out.println("\n\t EmployeeSessionBean--> public void initMethod() invoked");
@Remove(retainIfException=true)
public void removeWithRetain() throws Exception{
System.out.println("\n\t EmployeeSessionBean--> removeWithRetain() invoked");
@Remove
public void removeWithoutRetain() throws Exception{
System.out.println("\n\t EmployeeSessionBean--> removeWithoutRetain() invoked");
public String printRemoteIntf () {
System.out.println("\n\t EmployeeSessionBean ---> public String printRemoteIntf () invoked");
     return "ReplicableSFSRemoteObjectIntf";
public String printLocalIntf () {
System.out.println("\n\t EmployeeSessionBean ---> public String printLocalIntf () invoked");
     return "ReplicableSFSLocalObjectIntf";
public String printBean () {
System.out.println("\n\t EmployeeSessionBean ---> public String printBean () invoked");
     return "EmployeeSessionBean";
public int testIncrement() throws Exception
System.out.println("\n\t EmployeeSessionBean ---> public int testIncrement() invoked");
count=count+5;
return count;
public int testDecrement() throws Exception
System.out.println("\n\t EmployeeSessionBean ---> public int testDecrement() invoked");
count=count-2;
return count;
public int getCount() throws Exception
System.out.println("\n\t EmployeeSessionBean ---> public int getCount() invoked");
return count;
"*EmployeeSessionRemoteIntf.java*"
package sfsbA;
public interface EmployeeSessionRemoteIntf {
public void createEmployee(Long emono,String empname)     throws Exception;
public void removeWithRetain()throws Exception;
public void removeWithoutRetain() throws Exception;
public String printBean ();
public int testIncrement() throws Exception;
public int testDecrement() throws Exception;
public int getCount() throws Exception;
*"ejb-jar.xml"*
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
<enterprise-beans>
<session>
<ejb-name>EmployeeSessionBean</ejb-name>
<business-remote>sfsbA.EmployeeSessionRemoteIntf</business-remote>
<ejb-class>sfsbA.EmployeeSessionBean</ejb-class>
<session-type>Stateless</session-type>
</session>
</enterprise-beans>
</ejb-jar>
*"weblogic-ejb-jar.xml"* (I am writing these file Just because i want my Own JNDI Simple name...Not the Container Generated Complex JNDI name)
<weblogic-ejb-jar xmlns="http://www.bea.com/ns/weblogic/90" xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-ejb-jar.xsd">
<weblogic-enterprise-bean>
<ejb-name>EmployeeSessionBean</ejb-name>
<stateless-session-descriptor>
     <business-interface-jndi-name-map>
<business-remote>sfsbA.EmployeeSessionRemoteIntf</business-remote>
<jndi-name>EmployeeSessionBean</jndi-name>
     </business-interface-jndi-name-map>
</stateless-session-descriptor>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
"*application.xml*"
<!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'>
<application>
<display-name>JPAs_Demo_Jason</display-name>
<module>
<ejb>AccessEntityManager.jar</ejb>
</module>
</application>
NOTE: The Jar "" Contains
1). EmployeeSessionBean
2). EmployeeSessionRemoteIntf
3). META-INF/ejb-jar.xml
4). META-INF/weblogic-ejb-jar.xml
Thanks
Jay SenSharma
http://jaysensharma.wordpress.com  (Real WebLogic Stuff...Not less Than a Magic...Here)
Edited by: Jay SenSharma on Dec 16, 2009 10:59 PM
Edited by: Jay SenSharma on Dec 16, 2009 11:00 PM

Similar Messages

  • My Mountain Lion app failed while downloading, and now I can't download it without repaying for it.  How can I get my access code to work/download the app?

    My Mountain Lion app failed while downloading, and now I can't download it without repaying for it.  How can I get my access code to work/download the app?

    Welcome to Apple Support Communities
    Open App Store, select Account in Quick Links and press Show hidden purchases. If OS X isn't there, http://www.apple.com/support/mac/app-store/contact

  • I bought an application in itunes. When i opened the application, it asked me the access key that was sent throught my email address. But when i open my email address, there was no message from apple. how was that? where can i get the access key?

    i bought an application in itunes. When i opened the application, it asked me the access key that was sent throught my email address. But when i open my email address, there was no message from apple. how was that? where can i get the access key?

    Apple doesn't send access keys for apps. Which app was this?

  • I have dial-up, ipod touch, a wi-fi dongle, win7, and patience, can I get net access on my pod?

    I have dial-up, ipod touch, a wi-fi dongle, win7, and patience, can I get net access on my pod?

    Yes but it might be too slow for some purposes.  Google for the instructions for setting upu your win 7 comnputer as a wifi hotspot.  I Googled for:
    windows 7 as wifi hotspot
    and go many hits that look good.

  • Can i get wireless access with a 10.4.11

    Can I get wireless access on the internet with a Dual core intel processor 10.4.11

    If it has an Airport card fitted, yes.
    It's very likely it already has, but to be certain, go to the Apple menu > "about this Mac" > More info
    Under Network in the left pane you'll see Airport' select that and it'll tell you what card is fitted (if any).
    You should also have in the menu bar on the right a pie-slice type symbol; click that and you'll get the option to switch on airport if it's present.
    You'll need to set it up in Network Preferences to connect to your wi-fi router.

  • I HAVE AN IPAD 2 WITH WIFI ONLY, CAN I GET INTERNET ACCESS FROM ANY SMARTPHONE, OR DO I NEED A SPECIFIC PHONE FOR THIS?

    i ave an ipad 2 with wifi only, can i get internet access from any cell phone, or do i need a specific phone or type of phone

    I received an iPad 2 for Christmas (the 1st Apple item I've ever owned!) and own a Nokia N95 8GB mobile (that's pretty much on its last legs/ready to die any day).
    On the Nokia I've got 2 apps (downloaded from/via Nokia's 'Ovi' app store): JoikuSpot &amp; HandyWi. Both are the free versions.
    I've not used HandyWi much - if at all - but JoikuSpot has been great. Basically, it creates a wifi hotspot (as pjl123 mentioned) in a couple of straightforward steps, and allows a few devices to be connected. It displays who/what is connected at a given time - so you can check if the guy having coffee behind you is piggybacking your hotspot or not! - data packets sent received etc.
    The paid version has the benefit of allowing you to secure the hotspot and other security features.  Their website is www.joiku.com, FYI.
    Given how slow behind the 8 ball Nokia has been, their phones are getting cheaper and cheaper - given Joiku's meant to work with Nokia S60, Symbian ^3, Maemo, Meego &amp; Sony Ericsson S60, this might be a cost effective option.
    Ps. Ah! One more thing - Joiku's website specifies that 3G must be used; that WAP will not work. Good luck, enjoy!

  • Can't get internet access unless I am at home...

    I can't get internet access, use my navigation or get messages unless I am at home. I have tried everything, and don't know what else to do. Please HELP any suggestions would be appreciated! Thank you!

    Hi nthompson77,
    Welcome to BlackBerry Support Community Forums.
    Do you have a data plan with your wireless provider that supports internet browsing and messaging?
    If you do, is your signal uppercase or lowercase when you're having this issue? Have you tried reinserting your battery?
    -FS
    Come follow your BlackBerry Technical Team on Twitter! @BlackBerryHelp
    Be sure to click Kudos! for those who have helped you.
    Click Solution? for posts that have solved your issue(s)!

  • Can somebody explain to me how JSP, servlets, ASP work within Sun's server

    Ok, I'm only beginning to get a grip of how all this works. And I have a lot of questions and confusion.
    1.) The server that comes with J2EE, what is that server? Is it an app server that runs only servlets and JSP, with some Web server stuff so it can output some info? Is it a stripped down version of TomCat? I am having a lot of trouble with the J2EE server (the one that comes with the SDK), and that is why I'm asking, maybe I don't need it. But I really want to learn JSP's, JScripts, and Beans. How else can I go about doing that, other than all out Tomcat.
    2.) Also can I run Servlets on Microsft's IIS on a Windows 2000 machine? Do I need a special API to run servlets, or JSPs?
    So how I see it, and again, I am a newbie at this. Machines that host a website, above all needs a web server. let's say most people use Apache, and they want to run it in Linux, becuase they want to be hackers. So then do they also run Tomcat, or IIS, or Coldfusion, or a million other servers in tandem on the same machine, so that they can handle ASP, JSPs, servlets, .cmf, etc.? or do they separate the app server from the webserver and then do some sort of linking? if somebody can direct me to how all this stuff works, I would greatly greatly appreciate it.

    Sounds like you need to read the J2EE spec as well as
    the servlet and JSP specs. It helps to glance through
    sections you are interested in.
    Ok, I'm only beginning to get a grip of how all this
    works. And I have a lot of questions and confusion.
    I think for a newbie, deploying your jsp's and servlets
    to a J2EE compliant app server can be quite a headache.
    You might want to concentrate on tomcat, which does servlet
    and jsp.
    Some app servers provide a http connector for most common web servers.
    I think tomcat has a IIS connector. In this case IIS would serve static html as well as its own stuff, other things like servlets and jsp go to tomcat. I am unsure about this as I mostly use tomcat in standalone mode. You can run tomcat on windows, as it is written in java.
    >
    2.) Also can I run Servlets on Microsft's IIS on a
    Windows 2000 machine? Do I need a special API to run
    servlets, or JSPs?

  • Get Browser informations in JSP/Servlets

    How can I get informations (name...) about the browser who call my servlet ??
    Please help me

    Hi,
    Use the HTTP Request Headers
    eg, to get the browser request the User-Agent header
    request.getHeader("User-Agent");You can enumerate through headers
    Enumeration headers = request.getHeaderNames();
    while (headers.hasMoreElements()) {
    String name = (String)headers.nextElement();
    // the header name
    out.print(name + ": ");
    // the headers value
    out.println(request.getHeader(name));
    }Richard

  • Can't get internet access with WRT54G router

    I recently purchased a used WRT54G. I replaced my old wired linksys router with it and my hosts are able to get dhcp addresses from the router, but they cannot access the Internet. I have tried to use dchp release and renew buttons under the status tab in the router's web-based gui to get a public IP address, but can't get one. I have attempted to reset the router to its factory settings, but I still can't get the public IP. I have no problem getting an IP and Internet access with my old router and the WRT54G works if I disable its dchp and daisy chain it to the old one. Maybe I need to do something else for a complete reset of the router. Any suggestions? Thanks, Jack

    the router that you just purchased was maybe configured for a different network before that's why it did not work initially. after making the router back to its' factory defaults, you should reconfigure or set-up the router.. If you have CABLE ISP, enable ''mac address clone'' on the router's set-up page under the set-up tab. then check if you can get a public ip address after that.

  • Can't get internet access to computer based DVR

    I have a computer based DVR  (security cameras), that I want to be able to see through the internet. I have done a lot of reading on the net for how to set port forwarding in both the router (Linksys  WRT54G) and the modem (Westell 6100G). I can access the camera computer from other computers on the LAN using the camera computer local IP or by using the router IP, but can’t get to the camera computer from the internet. The modem is bridged  and I created a port forward to the camera computer both in the modem and router. What am I missing?

    I apologize I didn't realize it was a linksys router
    http://www.portforward.com/english/routers/port_forwarding/Linksys/WRT54Gv2.04/DINA_DVR_Server.htm
    This is a similiar set up and linksys requires that you put a port number for the start. 
    it looks like it wants the same number as the end
    so 9000 start  and 9000 end
    take a look at that site, and tell me if that helps.   sorry about that.

  • My I cloud is linked to an email address that is no longer valid and I forgot the password so can't get any access? Help

    O2 have discontinued my email address and I have forgotten my password. This email is the 1 I used for my iCloud account. So now can't get into my account at all? As if I do the forgot password thing it can't be verified through my email?

    Go to https://getsupport.apple.com ; click' See all products and services', then 'More Products and Services, then 'Apple ID', then 'Other Apple ID Topics' then 'Lost or forgotten Apple ID password'.

  • Can I get wifi access with my iphone 4 verizon in china?

    I have an iphone 4 with Verizon.  I have been told I can't get phone service, but have also been told I can get to the internet in hotels with wifi to get my webmail.  Is this true?  Will Google translate work under these conditions?  Maps?

    WiFi should work anywhere in the world. China blocks a lot of sites including (last I heard) the non-Chinese version of Google, though, so whether or not you'll be able to use Google Translate I don't know. I don't see Translate on the Google Hong Kong site, so it seems doubtful, but someone else here may know.
    Regards.

  • How can i get a file object on servlet

    i want to send a file object to be sent on a servlet from html input file tag. This is the HTML code
    <form action="uploadImage.jsp" method="post"><br><br>
                <table width="400px" align="center" border=0 style="background-color:ffeeff;">
                    <tr>
                        <td align="center" colspan=2 >
                            Image Details</td>
                    </tr>
                    <tr>
                        <td align="center" colspan=2> </td>
                    </tr>
                    <tr>
                        <td>Image Link: </td>
                        <td>
                            <input type="file" name="filename" id="file">                     
                        <td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><input type="submit" name="Submit" value="Submit"></td>
                    </tr>
                    <tr>
                        <td colspan="2"> </td>
                    </tr>
                </table>
            </form>On servlet i have tried this code.
                                    String file = request.getParameter("filename");
                                        if (file != null) {
                                            out.println(file);
                                            File f = new File(file);
                                            out.println(f.isFile());
                                            out.println(f.length());
                                        }this code is showing following output.
           DSC01347.JPG false 0 so is there any way of transferring the the file on servlet without using common file upload?
    Please help me

    i have worked out this following solution. It is working here.
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.PrintWriter;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Properties;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.Part;
    * @author Chinmay
    public class NewServlet extends HttpServlet {
         * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            Part p = request.getPart("file");
            out.println(p.getContentType());
            out.println(p.getName());
            out.println(p.getSize());
            InputStream in = (InputStream) p.getInputStream();
            byte[] b = new byte[in.available()];
            in.read(b,0,b.length);
            Connection connection = null;
            PreparedStatement stmt = null;
            try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Properties properties = new Properties();
            connection = DriverManager.getConnection("jdbc:odbc:sn", properties);
            stmt = connection.prepareStatement("insert into Photos(username,photo) values(?,?)");       
            stmt.setString(1, "a");
            stmt.setBytes(2, b);
            int rows = stmt.executeUpdate();
            if (rows > 0) {
            out.println("INSERTED");
            } catch (ClassNotFoundException ex) {
            out.println(ex);
            } catch (SQLException ex) {
            out.println(ex);
            } finally {
            in.close();
            try {
            connection.close();
            stmt.close();
            } catch (SQLException ex) {
            ex.printStackTrace();
            out.close();
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
         * Handles the HTTP <code>GET</code> method.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
         * Handles the HTTP <code>POST</code> method.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
         * Returns a short description of the servlet.
         * @return a String containing servlet description
        public String getServletInfo() {
            return "Short description";
        }// </editor-fold>
    }this code is storing the image in database.
    But not the main problem is this code is working on my PC. But when i executed this code at my institute's PC it shows me error that cannot find symbol for this line.
    import javax.servlet.http.Part;In my institute we have Netbeans 5.5.1 and tomcat server or sun app server.
    On my PC I have Netbeans 6.9.1 and Glassfish server.
    So what can be the problem?
    Is it a problem of server or just servlet's jar file???

  • Static methods in class accessed by jsp/servlet

    I wanted to conceptually know ...
    If I have a class specifically doing some quering to database and giving results to jsp and servlet ... does this make sense? Static methods are ok ? Is it secure enough if I have all connection classes local to a method? can i make the connection global instead without compromising security ?
    For example:
    public class DatabaseUtility{
    public static Sring getUsername(String employeeid)
      Connection conn = ...........
      Statement stmt = ........
    rs executes query and gets a username and returns it...
    public static Sring getAddress(String employeeid)
      Connection conn = ...........
      Statement stmt = ........
    rs executes query and gets a address and returns it...
    }

    can i make the connection global instead without compromising security ?As long as it was readonly, it should be secure. However as damiansutton said, you open yourself up to a resource bottleneck if you make the connection static, as everyone will be using the same connection.
    Most often if you want one piece of information from this DatabaseUtility, you want more than one. Why get a database connection each time? You want to get a DB connection, milk all the info you want from it, and then give it back.
    I think you might want to look at having a DataAccessObject: http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
    It is no longer static, but is much more efficient in that it only creates one database connection for all your queries on one request. So anywhere you want to use this, you create a new DatabaseUtility object, and then use it to your hearts content.
    Cheers,
    evnafets

Maybe you are looking for

  • Old apple tv can no longer sync back to computer

    I have an old apple tv that I would sync movies and tv shows for my kids. This way if the network wasn't working properly my wife could still put on a show. Recently all of the shows in my tv shows or my movies is gone and i now need to go to my shar

  • Mac.Mini and Mavericks failure

    Hey there,I am trying to upgrade a 2011 mac mini to.mavericks. The installer quits with a failure notice and then restarts only to fail again. I am stuck in the loop. Does anyone have any advice on this situation. Thanks for any help and advice.

  • How to drop datafiles in oracle 10g r2

    Hi all, Db :oracle 10.2.0.3 os:solaris 10 tablespace name: jllp_tabs01 datafile: /ora/data001/jllp/jllp_tbs01_tbl_1.dbf /ora/data001/jllp/jllp_tbs01_tbl_2.dbf /ora/data001/jllp/jllp_tbs01_tbl_3.dbf /ora/data001/jllp/jllp_tbs01_tbl_4.dbf its has consi

  • Relinking missing things in Folio Builder

    Hi, folks I usually work with CS6 in a desktop with Windows 7 but I have to finish my work with a MacBook due to the constraints imposed by Adobe DPS. That said, I sometimes need to work in a different computer (at the job, somewhere else...). To spe

  • Safari history disappeared before my eyes

    I was viewing my history (first time since upgrading to Yosemite) and whilst doing so, and without touching anything, my history disappeared except for 2 sites for yesterday (I had viewed dozens yesterday and was in the middle of looking for one of t